結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー tentententen
提出日時 2021-01-26 16:09:12
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,230 bytes
コンパイル時間 2,096 ms
コンパイル使用メモリ 76,636 KB
実行使用メモリ 58,128 KB
最終ジャッジ日時 2023-09-05 20:02:33
合計ジャッジ時間 14,459 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,792 KB
testcase_01 AC 123 ms
55,952 KB
testcase_02 AC 122 ms
55,972 KB
testcase_03 AC 121 ms
56,060 KB
testcase_04 AC 123 ms
55,956 KB
testcase_05 AC 123 ms
55,712 KB
testcase_06 AC 122 ms
55,900 KB
testcase_07 AC 123 ms
55,656 KB
testcase_08 AC 124 ms
56,012 KB
testcase_09 AC 122 ms
55,724 KB
testcase_10 AC 123 ms
55,644 KB
testcase_11 AC 124 ms
55,608 KB
testcase_12 AC 123 ms
55,864 KB
testcase_13 AC 126 ms
55,600 KB
testcase_14 AC 125 ms
55,428 KB
testcase_15 AC 127 ms
55,712 KB
testcase_16 AC 129 ms
55,648 KB
testcase_17 AC 127 ms
55,492 KB
testcase_18 AC 123 ms
55,888 KB
testcase_19 AC 126 ms
55,816 KB
testcase_20 AC 127 ms
55,756 KB
testcase_21 AC 127 ms
55,936 KB
testcase_22 AC 150 ms
55,924 KB
testcase_23 AC 126 ms
55,892 KB
testcase_24 AC 143 ms
56,120 KB
testcase_25 TLE -
testcase_26 AC 143 ms
56,356 KB
testcase_27 AC 142 ms
56,180 KB
testcase_28 AC 145 ms
56,260 KB
testcase_29 AC 144 ms
56,200 KB
testcase_30 AC 365 ms
56,256 KB
testcase_31 AC 224 ms
56,328 KB
testcase_32 AC 169 ms
55,916 KB
testcase_33 AC 691 ms
56,180 KB
testcase_34 AC 318 ms
58,128 KB
testcase_35 AC 588 ms
55,928 KB
testcase_36 AC 178 ms
56,052 KB
testcase_37 AC 175 ms
56,272 KB
testcase_38 AC 315 ms
56,124 KB
testcase_39 AC 302 ms
56,076 KB
testcase_40 AC 329 ms
55,904 KB
testcase_41 AC 653 ms
56,396 KB
testcase_42 AC 704 ms
55,916 KB
testcase_43 AC 144 ms
56,556 KB
testcase_44 AC 144 ms
56,244 KB
testcase_45 AC 123 ms
55,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long low = sc.nextLong();
        long high = sc.nextLong();
        long p = (long)Math.sqrt(high);
        boolean[] isNotPrime = new boolean[(int)p + 1];
        ArrayList<Integer> primes = new ArrayList<>();
        for (int i = 2; i < isNotPrime.length; i++) {
            if (!isNotPrime[i]) {
                primes.add(i);
                for (int j = 2; j * i < isNotPrime.length; j++) {
                    isNotPrime[j * i] = true;
                }
            }
        }
        for (int i = primes.size() - 1; i >= 0; i--) {
            int ans = primes.get(i);
            long out = 0;
            for (long j = (low + ans - 1) / ans; j * ans <= high; j++) {
                boolean notDivide = true;
                for (int k = 0; k < i && notDivide; k++) {
                    notDivide = (j % primes.get(k) != 0);
                }
                if (notDivide) {
                    out = Math.max(out, ans * j);
                }
            }
            if (out > 0) {
                System.out.println(out);
                return;
            }
        }
    }
}
0