import java.util.Scanner;
public class PrimeFactor {
//读入一个数,输出该数的因式分解式子
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int num=sc.nextInt();
int fac;
System.out.print(num+"=");
for (;num>1;){
fac=factor(num);
num/=factor(num);
System.out.print(fac);
if (num>1){
System.out.print("x");
}
}
}
//0~5000的质数表
public static int[] primeList(){
int cnt = 0;
int[] arrPrime=new int[669];
for (int i = 2; i <= 5000; i++) {
boolean is = true;
for (int j = 2; j < i; j++) {
if (i % j == 0) {
is = false;
break;
}
}
if (is) {
arrPrime[cnt]=i;
cnt++;
}
}
return arrPrime;
}
//输入一个小于十万的数,返回该数最小的质因数
public static int factor(int num){
int k=1;
for (int i:primeList()){
if (num%i==0){
k=i;
break;
}
}
return k;
}
}
————————————————
版权声明:本文为CSDN博主「学习12138000」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_42193009/article/details/105438648