結果

問題 No.36 素数が嫌い!
ユーザー t8m8⛄️t8m8⛄️
提出日時 2015-04-04 02:07:01
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,574 bytes
コンパイル時間 3,381 ms
コンパイル使用メモリ 76,984 KB
実行使用メモリ 106,332 KB
最終ジャッジ日時 2023-09-17 04:03:01
合計ジャッジ時間 10,071 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 185 ms
81,284 KB
testcase_01 AC 219 ms
96,216 KB
testcase_02 RE -
testcase_03 AC 123 ms
55,736 KB
testcase_04 AC 124 ms
55,996 KB
testcase_05 AC 127 ms
56,012 KB
testcase_06 AC 129 ms
55,740 KB
testcase_07 AC 130 ms
55,468 KB
testcase_08 AC 128 ms
55,832 KB
testcase_09 AC 126 ms
55,812 KB
testcase_10 AC 125 ms
55,784 KB
testcase_11 AC 189 ms
72,960 KB
testcase_12 AC 271 ms
106,332 KB
testcase_13 AC 267 ms
106,136 KB
testcase_14 AC 198 ms
87,776 KB
testcase_15 AC 122 ms
56,276 KB
testcase_16 AC 124 ms
56,196 KB
testcase_17 AC 122 ms
55,996 KB
testcase_18 AC 123 ms
56,180 KB
testcase_19 AC 180 ms
77,608 KB
testcase_20 AC 252 ms
106,272 KB
testcase_21 AC 217 ms
93,704 KB
testcase_22 AC 221 ms
96,024 KB
testcase_23 AC 184 ms
81,324 KB
testcase_24 AC 201 ms
83,584 KB
testcase_25 AC 190 ms
83,592 KB
testcase_26 AC 215 ms
87,756 KB
testcase_27 AC 245 ms
100,232 KB
testcase_28 AC 215 ms
87,636 KB
testcase_29 AC 266 ms
103,968 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();
        if (n == 1) {
            out.println("NO");
            return;
        }
        int[] primes = sieveOfEratosthenes((int)sqrt(n));
        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