题解 | #质数因子#
质数因子
http://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
while(sc.hasNext()){
long n = sc.nextLong();//用long是防止int溢出
long k = (long)Math.sqrt(n);
for(long i=2;i<=k;i++){
while(n%i==0){
System.out.print(i+" ");
n =n/i;//每次要把当前i除尽
}
}
//如果上面能全部整除,此时n=1,就不需要在打印,否则需打印n
System.out.print(n==1?"":n+" ");
}
}
}