输入一个long型整数
按照从小到大的顺序输出它的所有质数的因子,以空格隔开。最后一个数后面也要有空格。
解题思路
1、先把所有2除尽,再把所有3除尽,再到4的时候已经没有,在把所有5除尽
2、一直往下,可以得到质数因子
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
long lg = sc.nextLong();
int i = 2;
//解题思路
//先把所有2除尽,再把所有3除尽,再到4的时候已经没有,在把所有5除尽
//一直往下,可以得到质数因子
while(lg > 1){
if(lg % i == 0){
lg = lg / i ;
System.out.print(i + " ");
}
else
i++;
}
}
}
}