题解 | #质数因子#

质数因子

http://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607

import java.util.*;
public class Main {
    static TreeSet<Integer> set = new TreeSet<>();
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int left = 2, right = a;
        while (left < right) {
            if (a % left == 0) {
                set.add(left);
                set.add(a / left);
            }
            right = a / left + 1;
            left++;
        }
        set.add(a);
        for (int i : set) {
            while (a % i == 0) {
                System.out.print(i + " ");
                a /= i;
            }
        }
    }
}
全部评论

相关推荐

评论
4
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务