結果
| 問題 |
No.1657 Sum is Prime (Easy Version)
|
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2021-08-27 21:39:59 |
| 言語 | Java (openjdk 23) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,244 bytes |
| コンパイル時間 | 3,957 ms |
| コンパイル使用メモリ | 85,200 KB |
| 実行使用メモリ | 71,640 KB |
| 最終ジャッジ日時 | 2024-11-21 01:17:25 |
| 合計ジャッジ時間 | 8,801 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 RE * 1 |
| other | AC * 15 WA * 5 RE * 1 |
ソースコード
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int l = sc.nextInt();
int r = sc.nextInt();
sc.close();
Eratosthenes era = new Eratosthenes(r * 5);
int ans = 0;
for (int i = l; i <= r; i++) {
int sum = 0;
for (int j = i; j <= i + 3; j++) {
sum += j;
if (era.isSosuu(sum)) {
ans++;
}
}
}
System.out.println(ans);
}
static class Eratosthenes {
int[] div;
public Eratosthenes(int n) {
if (n < 2) return;
div = new int[n + 1];
div[0] = -1;
div[1] = -1;
int end = (int) Math.sqrt(n) + 1;
for (int i = 2; i <= end; i++) {
if (div[i] == 0) {
div[i] = i;
for (int j = i * i; j <= n; j+=i) {
if (div[j] == 0) div[j] = i;
}
}
}
for (int i = end + 1; i <= n; i++) {
if (div[i] == 0) div[i] = i;
}
}
public Map<Integer, Integer> bunkai(int x) {
Map<Integer, Integer> soinsu = new HashMap<>();
while (x > 1) {
Integer d = div[x];
soinsu.put(d, soinsu.getOrDefault(d, 0) + 1);
x /= d;
}
return soinsu;
}
public boolean isSosuu(int x) {
return div[x] == x;
}
}
}
ks2m