Home > Back-end >  Blue cup of decomposition of prime factors
Blue cup of decomposition of prime factors

Time:10-01

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

Public class Main {
Public static void main (String [] args) {
Scanner sc=new Scanner(System.in);
Int m=sc nextInt ();
Int n=sc. NextInt ();
The StringBuilder sb=new StringBuilder ();
While (m<=n) {
Map Map1=primeFactor (m);
For (Map. Entry Entry: map1 entrySet ()) {
Int k=entry. GetKey ();
Int v=entry. The getValue ();
for (int i=0; I & lt; V. I++) {
Sb. Append (" * "+ k);
}
}
System. The out. Println (m + "=" + sb. The substring (1));
Sb. Delete (0, sb. The length ());
+ + m;
}

}

Public static Map PrimeFactor (int num) {
Map The map=new HashMap<> (a);//prime factors - occurrences
If (isPrime (num)) {
Integer v=map. Get (num);
If (n==null)
The map. The put (num, 1);
The else
Map. The put (num, v + 1);
}
The else {
For (int I=2; I & lt; Num=; I++) {
I==0) while (num % {
The Integer v=map. Get (I);
If (n==null)
The map. The put (I, 1);
The else
Map. The put (I, v + 1);
Num/=I;
}
}
}
Return the map;
}

Public static Boolean isPrime (int num) {
For (int I=2; I * I & lt; Num=; I++) {
If (num % I==0) return false.
}
return true;
}
}

Run and test cases as why always an error

CodePudding user response:

refer to the original poster weixin_41606555 response:
run and test cases as oh why always error


Quote what error, the error posted, program seems to be no problem!

CodePudding user response:

No error, is the test case
  • Related