题解 | #质数因子#
质数因子
https://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { long n = sc.nextLong(); long k = (long) Math.ceil(Math.sqrt(n)); for (int i = 2; i <= k; i++) { while (n % i == 0 && k != 1) { System.out.print(i + " "); n = n / i; } } // 防止最后为质数 if (n != 1) { System.out.println(n); } System.out.println(); } } }