結果
| 問題 | No.407 鴨等素数間隔列の数え上げ |
| コンテスト | |
| ユーザー |
ぴろず
|
| 提出日時 | 2016-08-16 21:48:09 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
AC
|
| 実行時間 | 135 ms / 1,000 ms |
| コード長 | 1,057 bytes |
| 記録 | |
| コンパイル時間 | 2,337 ms |
| コンパイル使用メモリ | 82,976 KB |
| 実行使用メモリ | 58,684 KB |
| 最終ジャッジ日時 | 2026-05-26 05:53:18 |
| 合計ジャッジ時間 | 8,394 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 5 |
| other | AC * 31 |
ソースコード
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;
}
}
ぴろず