。
import java.util.*;
public class Main{
public static void main(String[] args){ Scanner scanner = new Scanner(System.in); Long aLong = scanner.nextLong(); int a = (int) Math.sqrt(aLong) + 1; int i = 2; while (aLong != 1 && i <= a) { if (aLong % i == 0) { aLong /= i; System.out.print(i + " "); i = 2; } else {// 单纯暴力,可以优化为i只包含 '奇数(不含1)' 和'2',我懒 i++; } } if (i > a) {// 在2-->sqrt(n)中,无因数,输出自身 System.out.print(aLong + " "); } scanner.close(); }
}