結果

問題 No.3023 素数判定するだけ
ユーザー 宇宙猫宇宙猫
提出日時 2024-02-25 15:46:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 148 ms / 1,000 ms
コード長 2,159 bytes
コンパイル時間 3,018 ms
コンパイル使用メモリ 80,896 KB
実行使用メモリ 58,228 KB
最終ジャッジ日時 2024-02-25 15:47:03
合計ジャッジ時間 10,768 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
56,820 KB
testcase_01 AC 130 ms
57,968 KB
testcase_02 AC 129 ms
57,840 KB
testcase_03 AC 129 ms
57,712 KB
testcase_04 AC 127 ms
57,840 KB
testcase_05 AC 148 ms
57,968 KB
testcase_06 AC 128 ms
57,836 KB
testcase_07 AC 130 ms
57,820 KB
testcase_08 AC 131 ms
57,792 KB
testcase_09 AC 128 ms
57,828 KB
testcase_10 AC 148 ms
57,840 KB
testcase_11 AC 128 ms
57,972 KB
testcase_12 AC 128 ms
57,712 KB
testcase_13 AC 127 ms
57,820 KB
testcase_14 AC 128 ms
57,716 KB
testcase_15 AC 127 ms
58,076 KB
testcase_16 AC 130 ms
58,084 KB
testcase_17 AC 128 ms
58,088 KB
testcase_18 AC 128 ms
58,096 KB
testcase_19 AC 117 ms
56,816 KB
testcase_20 AC 130 ms
57,712 KB
testcase_21 AC 129 ms
58,116 KB
testcase_22 AC 118 ms
56,816 KB
testcase_23 AC 127 ms
57,844 KB
testcase_24 AC 129 ms
58,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.nio.file.StandardOpenOption;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.atomic.AtomicInteger;

public class Main {

    class $rem {}

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {

            $rem 大胆なコメント¥内部的には変数;
            $rem ft_batch_script;

            $rem ちなみにアスタリスクを用いた一括インポートは出来ないので;
            $rem プログラムが完成してからimportを展開する必要がある;

            $rem 詳細はJavaDocを参照;
            int thousand = " \b".hashCode();

            $rem 素数は英語じゃ綴れないので頭文字で代用;
            $rem 余談だがprimeのように全角文字で代用することも可能;
            List<Integer> p = new ArrayList<>();

            $rem 適当なenumの定義インデックスを拾ってくる¥2__________普通のインクリメント;
            loop:
            for (int i=StandardOpenOption.APPEND.ordinal();i<=thousand;i=new AtomicInteger(i).incrementAndGet()) {
                for (int num : p) {
                    $rem 剰余演算子は禁止されていない;
                    $rem _v_________v_BigIntegerの汎用値ゼロをint変換;
                    if (i % num == BigInteger.ZERO.intValue())
                        continue loop;
                    $rem 掛け算にはMathクラスを使う方法もある;
                    if (i < Math.multiplyExact(num, num)) break;
                }
                p.add(i);
            }
            int n = scanner.nextInt();
            $rem 素数一覧からnを二分探索________長さ0の配列の長さ¥つまり0と比較;
            if (Collections.binarySearch(p, n) < new int[]{}.length) {
                System.out.println("NO");
            } else {
                System.out.println("YES");
            }
        }
    }

	void 制作完了時点で警告44とか出てておもろい() {}

}
0