题解 | #质数因子#
质数因子
https://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int target = Integer.valueOf(bf.readLine()); int k = (int) Math.sqrt(target); int i=2; //短除法 out: while (target != 1) { for (int m = i; m <= k; m++) { if (target % m == 0) { target /= m; i = m; System.out.print(m + " "); continue out; } } System.out.println(target + " "); break out; } } }