站在巨人肩膀上的答案
一般遇到判断质数的题,样例往往会有个特别大的质数,所以for遍历的时候要遍历sqrt(num);
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long num = sc.nextInt();
long sqr = (long)Math.sqrt(num);
for (long i = 2; i <= sqr; ++i) {
while (num % i == 0) {
System.out.print(i + " ");
num /= i;
}
}
if(num != 1)
System.out.println(num);
}
}