結果

問題 No.371 ぼく悪いプライムじゃないよ
ユーザー htensaihtensai
提出日時 2020-02-13 15:54:04
言語 Java19
(openjdk 21)
結果
AC  
実行時間 163 ms / 1,000 ms
コード長 1,027 bytes
コンパイル時間 2,117 ms
コンパイル使用メモリ 71,912 KB
実行使用メモリ 56,116 KB
最終ジャッジ日時 2023-07-28 12:38:15
合計ジャッジ時間 10,019 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,696 KB
testcase_01 AC 129 ms
55,812 KB
testcase_02 AC 128 ms
55,672 KB
testcase_03 AC 125 ms
55,740 KB
testcase_04 AC 124 ms
55,796 KB
testcase_05 AC 127 ms
55,592 KB
testcase_06 AC 126 ms
56,076 KB
testcase_07 AC 126 ms
55,896 KB
testcase_08 AC 126 ms
55,448 KB
testcase_09 AC 124 ms
55,672 KB
testcase_10 AC 124 ms
55,772 KB
testcase_11 AC 127 ms
55,676 KB
testcase_12 AC 125 ms
56,008 KB
testcase_13 AC 126 ms
56,116 KB
testcase_14 AC 126 ms
55,572 KB
testcase_15 AC 123 ms
55,724 KB
testcase_16 AC 125 ms
55,652 KB
testcase_17 AC 126 ms
55,460 KB
testcase_18 AC 124 ms
55,604 KB
testcase_19 AC 123 ms
55,784 KB
testcase_20 AC 128 ms
55,620 KB
testcase_21 AC 123 ms
55,620 KB
testcase_22 AC 124 ms
56,016 KB
testcase_23 AC 125 ms
55,652 KB
testcase_24 AC 128 ms
55,768 KB
testcase_25 AC 129 ms
56,112 KB
testcase_26 AC 163 ms
55,740 KB
testcase_27 AC 129 ms
55,588 KB
testcase_28 AC 134 ms
55,664 KB
testcase_29 AC 130 ms
55,888 KB
testcase_30 AC 128 ms
55,832 KB
testcase_31 AC 128 ms
55,640 KB
testcase_32 AC 129 ms
53,312 KB
testcase_33 AC 128 ms
55,880 KB
testcase_34 AC 130 ms
55,352 KB
testcase_35 AC 129 ms
55,924 KB
testcase_36 AC 129 ms
56,048 KB
testcase_37 AC 129 ms
55,844 KB
testcase_38 AC 128 ms
55,492 KB
testcase_39 AC 127 ms
55,864 KB
testcase_40 AC 129 ms
55,852 KB
testcase_41 AC 128 ms
55,596 KB
testcase_42 AC 129 ms
55,596 KB
testcase_43 AC 130 ms
55,732 KB
testcase_44 AC 142 ms
55,804 KB
testcase_45 AC 126 ms
55,460 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