結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー YamaKasaYamaKasa
提出日時 2018-09-19 17:22:36
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 835 bytes
コンパイル時間 2,855 ms
コンパイル使用メモリ 74,736 KB
実行使用メモリ 64,396 KB
最終ジャッジ日時 2023-09-25 10:12:59
合計ジャッジ時間 10,333 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
60,552 KB
testcase_01 AC 118 ms
56,144 KB
testcase_02 AC 120 ms
55,472 KB
testcase_03 AC 186 ms
56,212 KB
testcase_04 AC 119 ms
55,836 KB
testcase_05 AC 119 ms
55,984 KB
testcase_06 AC 119 ms
55,708 KB
testcase_07 AC 121 ms
55,916 KB
testcase_08 AC 123 ms
55,832 KB
testcase_09 AC 122 ms
55,940 KB
testcase_10 AC 120 ms
55,764 KB
testcase_11 AC 120 ms
54,076 KB
testcase_12 AC 128 ms
56,068 KB
testcase_13 AC 116 ms
55,848 KB
testcase_14 AC 120 ms
55,752 KB
testcase_15 AC 119 ms
56,180 KB
testcase_16 AC 127 ms
55,724 KB
testcase_17 AC 114 ms
55,524 KB
testcase_18 AC 120 ms
56,000 KB
testcase_19 AC 407 ms
57,916 KB
testcase_20 TLE -
testcase_21 AC 117 ms
55,964 KB
testcase_22 AC 118 ms
55,920 KB
testcase_23 AC 121 ms
55,988 KB
testcase_24 AC 122 ms
55,940 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int L = scan.nextInt();
		scan.close();
		int max = L / (N -1);
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 2; i <= max; i++) {
			if(isPrime(i)) {
				list.add(i);
			}
		}
		long cnt = 0;
		for(int i = 0; i < list.size(); i++) {
			if(L - (N - 1) * list.get(i) >= 0) {
				cnt += L - (N - 1) * list.get(i) + 1;
			}
		}
		System.out.println(cnt);
	}
	static boolean isPrime(int n) {
		if(n == 2) {
			return true;
		}
		if(n % 2 == 0) {
			return false;
		}
        for(long i = 2; i <= (int)Math.sqrt(n); i++){
            if(n % i == 0) {
                return false;
            }
        }
        return true;
    }
}
0