結果

問題 No.36 素数が嫌い!
ユーザー t8m8⛄️t8m8⛄️
提出日時 2015-04-04 02:08:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 282 ms / 5,000 ms
コード長 1,582 bytes
コンパイル時間 4,097 ms
コンパイル使用メモリ 75,060 KB
実行使用メモリ 106,352 KB
最終ジャッジ日時 2023-09-09 07:09:31
合計ジャッジ時間 10,533 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 187 ms
81,224 KB
testcase_01 AC 229 ms
95,380 KB
testcase_02 AC 128 ms
55,948 KB
testcase_03 AC 127 ms
55,920 KB
testcase_04 AC 126 ms
56,152 KB
testcase_05 AC 127 ms
55,324 KB
testcase_06 AC 132 ms
55,568 KB
testcase_07 AC 134 ms
55,580 KB
testcase_08 AC 126 ms
55,592 KB
testcase_09 AC 130 ms
55,732 KB
testcase_10 AC 131 ms
55,812 KB
testcase_11 AC 192 ms
72,856 KB
testcase_12 AC 282 ms
105,928 KB
testcase_13 AC 282 ms
105,948 KB
testcase_14 AC 207 ms
87,076 KB
testcase_15 AC 129 ms
55,876 KB
testcase_16 AC 127 ms
55,712 KB
testcase_17 AC 126 ms
55,552 KB
testcase_18 AC 125 ms
53,824 KB
testcase_19 AC 186 ms
76,956 KB
testcase_20 AC 257 ms
106,352 KB
testcase_21 AC 219 ms
93,492 KB
testcase_22 AC 221 ms
95,612 KB
testcase_23 AC 187 ms
81,328 KB
testcase_24 AC 205 ms
83,212 KB
testcase_25 AC 193 ms
83,076 KB
testcase_26 AC 219 ms
87,628 KB
testcase_27 AC 251 ms
99,980 KB
testcase_28 AC 218 ms
87,884 KB
testcase_29 AC 267 ms
104,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//No.36 素数が嫌い!

import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

public class No36 {
    
    static final Scanner sc = new Scanner(System.in);
    static final PrintWriter out = new PrintWriter(System.out,false);

    static void solve() {
        long n = sc.nextLong();
        int[] primes = sieveOfEratosthenes((int)sqrt(n));
        if (primes == null) {
            out.println("NO");
            return;
        }
        int cnt = 0;
        for (int i=0; i<primes.length; i++) {

            if (n%primes[i] == 0) cnt++;
            if (cnt == 2 || n%((long)primes[i]*primes[i]) == 0) {
                out.println("YES");
                return;
            }
        }
        out.println("NO");
    }

    static int[] sieveOfEratosthenes(int n) {
        if (n < 2) return null;
        boolean[] isPrime = new boolean[n];
        fill(isPrime,true);
        int[] res = new int[n];
        int ptr = 0;
        isPrime[0] = isPrime[1] = false;
        for (int i=2; i<n; i++) {
            if (isPrime[i]) {
                res[ptr++] = i;
                for (int j=i+i; j<n; j+=i) isPrime[j] = false;
            }
        }
        return Arrays.copyOfRange(res,0,ptr);
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();

        solve();
        out.flush();

        long end = System.currentTimeMillis();
        //trace(end-start + "ms");
        sc.close();
    }

    static void trace(Object... o) { System.out.println(deepToString(o));}
}
0