結果
| 問題 | No.407 鴨等素数間隔列の数え上げ |
| コンテスト | |
| ユーザー |
YamaKasa
|
| 提出日時 | 2018-09-19 17:47:05 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,067 bytes |
| 記録 | |
| コンパイル時間 | 2,093 ms |
| コンパイル使用メモリ | 77,020 KB |
| 実行使用メモリ | 46,300 KB |
| 最終ジャッジ日時 | 2024-07-18 08:19:14 |
| 合計ジャッジ時間 | 8,208 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 WA * 1 |
| other | AC * 29 WA * 2 |
ソースコード
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;
// }
}
YamaKasa