結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー YamaKasaYamaKasa
提出日時 2018-09-19 17:47:05
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,067 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 74,012 KB
実行使用メモリ 60,092 KB
最終ジャッジ日時 2023-09-25 10:14:17
合計ジャッジ時間 7,983 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 119 ms
55,720 KB
testcase_02 AC 119 ms
56,084 KB
testcase_03 AC 138 ms
55,716 KB
testcase_04 AC 121 ms
56,184 KB
testcase_05 AC 119 ms
56,172 KB
testcase_06 AC 119 ms
55,900 KB
testcase_07 AC 119 ms
55,968 KB
testcase_08 AC 122 ms
55,980 KB
testcase_09 AC 118 ms
55,492 KB
testcase_10 WA -
testcase_11 AC 123 ms
55,724 KB
testcase_12 AC 119 ms
55,720 KB
testcase_13 AC 120 ms
55,964 KB
testcase_14 AC 119 ms
55,948 KB
testcase_15 AC 120 ms
55,792 KB
testcase_16 AC 122 ms
55,944 KB
testcase_17 WA -
testcase_18 AC 122 ms
55,812 KB
testcase_19 AC 141 ms
54,164 KB
testcase_20 AC 144 ms
58,276 KB
testcase_21 AC 121 ms
55,796 KB
testcase_22 AC 120 ms
55,824 KB
testcase_23 AC 123 ms
55,568 KB
testcase_24 AC 122 ms
55,592 KB
testcase_25 AC 154 ms
58,388 KB
testcase_26 AC 123 ms
55,920 KB
testcase_27 AC 120 ms
56,036 KB
testcase_28 AC 119 ms
55,444 KB
testcase_29 AC 120 ms
55,712 KB
testcase_30 AC 120 ms
55,668 KB
testcase_31 AC 121 ms
55,976 KB
testcase_32 AC 147 ms
57,732 KB
testcase_33 AC 167 ms
59,776 KB
testcase_34 AC 166 ms
60,092 KB
testcase_35 AC 149 ms
57,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	static boolean[] isPrime;
	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);
		isPrime = new boolean[max + 1];
		long cnt = 0;
		if(max > 2) {
			aryPrime();
		}

		for(int i = 2; i < max + 1; i++) {
			if(isPrime[i]) {
				cnt += L - (N - 1) * i + 1;
			}
		}
		System.out.println(cnt);
	}
	static void aryPrime(){
		int l = isPrime.length;
		for(int i = 0; i < l; i++) {
			isPrime[i] = true;
		}
		isPrime[0] = false;
		isPrime[1] = false;
		for(int i = 2; i <= (int)Math.sqrt(l); i++) {
			if(isPrime[i]) {
				for(int j = i * 2; j < l; j += i) {
					isPrime[j] = false;
				}
			}
		}
	}
//	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