結果

問題 No.36 素数が嫌い!
ユーザー htensai
提出日時 2019-12-26 10:36:06
言語 Java
(openjdk 23)
結果
AC  
実行時間 220 ms / 5,000 ms
コード長 952 bytes
コンパイル時間 1,878 ms
コンパイル使用メモリ 75,424 KB
実行使用メモリ 41,760 KB
最終ジャッジ日時 2024-10-03 04:50:08
合計ジャッジ時間 6,815 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        HashMap<Long, Integer> map = new HashMap<>();
        for (long i = 2; i <= Math.sqrt(n); i++) {
            while (n % i == 0) {
                if (map.containsKey(i)) {
                    map.put(i, map.get(i) + 1);
                } else {
                    map.put(i, 1);
                }
                n /= i;
            }
        }
        if (n != 1) {
            if (map.containsKey(n)) {
                map.put(n, map.get(n) + 1);
            } else {
                map.put(n, 1);
            }
        }
        boolean flag = false;
        int sum = 0;
        for (int x : map.values()) {
            sum += x;
        }
        if (sum >= 3) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}
0