题解 | #质数因子#
质数因子
https://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); long number = in.nextLong(); // 只需计算开平方次,如果此时数字还没除数,则其为质数 long n = (long)Math.sqrt(number); for (long i=2; i<=n;i++){ while(number%i==0){ System.out.print(i+" "); number/=i; } } // 其为质数 System.out.print(number==1?"":number+" "); } }