結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー YamaKasaYamaKasa
提出日時 2018-09-19 17:29:03
言語 Java19
(openjdk 21)
結果
TLE  
実行時間 -
コード長 835 bytes
コンパイル時間 4,769 ms
コンパイル使用メモリ 79,624 KB
実行使用メモリ 62,788 KB
最終ジャッジ日時 2023-09-25 10:13:41
合計ジャッジ時間 11,202 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,460 KB
testcase_01 AC 122 ms
56,256 KB
testcase_02 AC 121 ms
55,828 KB
testcase_03 AC 148 ms
55,448 KB
testcase_04 AC 120 ms
55,976 KB
testcase_05 AC 120 ms
55,820 KB
testcase_06 AC 119 ms
55,708 KB
testcase_07 AC 121 ms
55,764 KB
testcase_08 AC 121 ms
55,804 KB
testcase_09 AC 122 ms
55,444 KB
testcase_10 AC 122 ms
55,832 KB
testcase_11 AC 127 ms
55,848 KB
testcase_12 AC 125 ms
55,444 KB
testcase_13 AC 121 ms
55,888 KB
testcase_14 AC 121 ms
55,848 KB
testcase_15 AC 122 ms
55,736 KB
testcase_16 AC 122 ms
55,828 KB
testcase_17 AC 123 ms
56,040 KB
testcase_18 AC 118 ms
55,824 KB
testcase_19 AC 181 ms
58,096 KB
testcase_20 AC 348 ms
60,476 KB
testcase_21 AC 119 ms
55,460 KB
testcase_22 AC 120 ms
55,656 KB
testcase_23 AC 119 ms
55,848 KB
testcase_24 AC 117 ms
56,012 KB
testcase_25 AC 542 ms
60,352 KB
testcase_26 AC 123 ms
55,960 KB
testcase_27 AC 121 ms
55,484 KB
testcase_28 AC 120 ms
55,832 KB
testcase_29 AC 118 ms
56,108 KB
testcase_30 AC 118 ms
55,432 KB
testcase_31 AC 120 ms
56,048 KB
testcase_32 AC 291 ms
57,484 KB
testcase_33 TLE -
testcase_34 TLE -
testcase_35 AC 493 ms
60,516 KB
権限があれば一括ダウンロードができます

ソースコード

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(int i = 3; i <= (int)Math.sqrt(n); i+=2){
            if(n % i == 0) {
                return false;
            }
        }
        return true;
    }
}
0