素数分解


素数分解
package _6    ;
import java.util.HashMap;
import java.util.Map;
//PrimeBunber      
//       8=2 4
public class l        {
public static void main(String[] args) {
 Map<Integer, Integer> map = primeFactor(100);
 
 StringBuilder sb=new StringBuilder();
 for(Map.Entry<Integer, Integer>entry:map.entrySet()) {
	 int k=entry.getKey();//      
	 int v=entry.getValue();//     
	 for(int i=0;i<v;i++) {
		 sb.append("*"+k);
	 }
 }
 System.out.println(map);
 System.out.println(sb.substring(1));
}
//     
private static Map<Integer, Integer> primeFactor(int m) {
	// TODO Auto-generated method stub
	Map<Integer,Integer>map=new HashMap<>();//          
	for(int i=2;i*i<=m;i++) {
		while(m%i==0) {
			Integer v=map.get(i);//  
			if(v==null) {
				map.put(i, 1);//     
			}else {
				map.put(i, v+1);
			}
			m/=i;
		}	
	}
	return map;//      
}
}

```![         ](https://img-blog.csdnimg.cn/20200804214225503.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NTk1MjcwNg==,size_16,color_FFFFFF,t_70)