题解 | #质数因子#
质数因子
http://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607
import java.util.Scanner;
public class Main{
private static boolean isPrime(int x){
for(int i = 2;i<=x/2;i++){
if(x%i == 0){
return false;
}
}
return true;
}
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
int i = 2;
while(n!=1){
if(isPrime(n)){
System.out.print(n + " ");
break;
}
while(n%i == 0){
System.out.print(i + " ");
n = n/i;
}
i+=1;
}
}
}
}