結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー htensaihtensai
提出日時 2020-02-13 15:54:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 154 ms / 1,000 ms
コード長 1,027 bytes
コンパイル時間 2,381 ms
コンパイル使用メモリ 75,036 KB
実行使用メモリ 41,636 KB
最終ジャッジ日時 2024-04-15 21:23:05
合計ジャッジ時間 8,636 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
41,256 KB
testcase_01 AC 118 ms
41,416 KB
testcase_02 AC 119 ms
41,236 KB
testcase_03 AC 107 ms
40,136 KB
testcase_04 AC 119 ms
41,368 KB
testcase_05 AC 116 ms
41,308 KB
testcase_06 AC 108 ms
40,264 KB
testcase_07 AC 118 ms
41,396 KB
testcase_08 AC 118 ms
41,280 KB
testcase_09 AC 116 ms
41,568 KB
testcase_10 AC 122 ms
41,360 KB
testcase_11 AC 118 ms
41,248 KB
testcase_12 AC 119 ms
41,264 KB
testcase_13 AC 122 ms
41,268 KB
testcase_14 AC 116 ms
40,932 KB
testcase_15 AC 116 ms
40,948 KB
testcase_16 AC 114 ms
41,148 KB
testcase_17 AC 118 ms
41,312 KB
testcase_18 AC 109 ms
40,008 KB
testcase_19 AC 107 ms
40,156 KB
testcase_20 AC 103 ms
39,740 KB
testcase_21 AC 116 ms
41,076 KB
testcase_22 AC 119 ms
41,320 KB
testcase_23 AC 120 ms
41,012 KB
testcase_24 AC 122 ms
41,188 KB
testcase_25 AC 112 ms
40,164 KB
testcase_26 AC 154 ms
41,264 KB
testcase_27 AC 123 ms
41,636 KB
testcase_28 AC 113 ms
40,164 KB
testcase_29 AC 106 ms
40,044 KB
testcase_30 AC 112 ms
40,128 KB
testcase_31 AC 122 ms
41,320 KB
testcase_32 AC 117 ms
40,264 KB
testcase_33 AC 109 ms
40,520 KB
testcase_34 AC 111 ms
40,060 KB
testcase_35 AC 112 ms
40,104 KB
testcase_36 AC 119 ms
41,536 KB
testcase_37 AC 120 ms
41,168 KB
testcase_38 AC 119 ms
41,488 KB
testcase_39 AC 106 ms
39,884 KB
testcase_40 AC 123 ms
40,192 KB
testcase_41 AC 123 ms
41,496 KB
testcase_42 AC 112 ms
40,168 KB
testcase_43 AC 124 ms
41,256 KB
testcase_44 AC 130 ms
41,312 KB
testcase_45 AC 108 ms
40,216 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 maxNumber = high / 2 * 2;
        for (long i = (long)(Math.sqrt(high)); i >= 3 ; i--) {
            if (!isPrime(i)) {
                continue;
            }
            for (long j = high / i * i; j >= low; j -= i) {
                if (getMax(j) >= i) {
                    System.out.println(j);
                    return;
                }
            }
        }
        System.out.println(maxNumber);
    }
    
    static long getMax(long x) {
        for (long i = 2; i <= Math.sqrt(x); i++) {
            if (x % i == 0) {
                return i;
            }
        }
        return x;
    }
    
    static boolean isPrime(long x) {
        for (long i = 2; i <= Math.sqrt(x); i++) {
            if (x % i == 0) {
                return false;
            }
        }
        return true;
    }
}
0