結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー ぴろずぴろず
提出日時 2016-08-16 21:48:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 234 ms / 1,000 ms
コード長 1,057 bytes
コンパイル時間 2,248 ms
コンパイル使用メモリ 79,344 KB
実行使用メモリ 67,576 KB
最終ジャッジ日時 2023-08-22 05:01:40
合計ジャッジ時間 12,352 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 224 ms
67,332 KB
testcase_01 AC 226 ms
67,024 KB
testcase_02 AC 225 ms
67,184 KB
testcase_03 AC 224 ms
64,692 KB
testcase_04 AC 225 ms
67,152 KB
testcase_05 AC 226 ms
67,460 KB
testcase_06 AC 221 ms
67,020 KB
testcase_07 AC 224 ms
66,740 KB
testcase_08 AC 222 ms
66,756 KB
testcase_09 AC 224 ms
67,104 KB
testcase_10 AC 224 ms
67,140 KB
testcase_11 AC 224 ms
67,064 KB
testcase_12 AC 224 ms
67,576 KB
testcase_13 AC 223 ms
66,800 KB
testcase_14 AC 222 ms
67,124 KB
testcase_15 AC 223 ms
66,796 KB
testcase_16 AC 223 ms
66,876 KB
testcase_17 AC 223 ms
67,144 KB
testcase_18 AC 223 ms
66,804 KB
testcase_19 AC 224 ms
67,036 KB
testcase_20 AC 229 ms
67,248 KB
testcase_21 AC 224 ms
67,100 KB
testcase_22 AC 224 ms
67,304 KB
testcase_23 AC 224 ms
65,156 KB
testcase_24 AC 225 ms
66,996 KB
testcase_25 AC 234 ms
67,100 KB
testcase_26 AC 222 ms
67,256 KB
testcase_27 AC 222 ms
67,032 KB
testcase_28 AC 224 ms
67,160 KB
testcase_29 AC 224 ms
67,028 KB
testcase_30 AC 225 ms
66,996 KB
testcase_31 AC 225 ms
67,048 KB
testcase_32 AC 223 ms
66,992 KB
testcase_33 AC 226 ms
66,716 KB
testcase_34 AC 227 ms
67,400 KB
testcase_35 AC 233 ms
66,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no407;

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		ArrayList<Integer> primes = Prime.primeList(5000010);
		long sum = 0;
		for(int p: primes) {
			long a = (long) p * (n - 1) + 1;
			long x = l + 2 - a;
			if (x >= 0) sum += x;
		}
		System.out.println(sum);
	}

}

class Prime {
	public static boolean[] isPrimeArray(int max) {
		boolean[] isPrime = new boolean[max+1];
		Arrays.fill(isPrime, true);
		isPrime[0] = isPrime[1] = false;
		for(int i=2;i*i<=max;i++) {
			if (isPrime[i]) {
				int j = i * 2;
				while(j<=max) {
					isPrime[j] = false;
					j += i;
				}
			}
		}
		return isPrime;
	}
	public static ArrayList<Integer> primeList(int max) {
		boolean[] isPrime = isPrimeArray(max);
		ArrayList<Integer> primeList = new ArrayList<Integer>();
		for(int i=2;i<=max;i++) {
			if (isPrime[i]) {
				primeList.add(i);
			}
		}
		return primeList;
	}
}
0