結果
問題 | No.1657 Sum is Prime (Easy Version) |
ユーザー | ks2m |
提出日時 | 2021-08-27 21:39:59 |
言語 | Java21 (openjdk 21) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,244 bytes |
コンパイル時間 | 2,544 ms |
コンパイル使用メモリ | 81,800 KB |
実行使用メモリ | 62,512 KB |
最終ジャッジ日時 | 2024-05-01 02:00:29 |
合計ジャッジ時間 | 7,777 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | AC | 137 ms
41,460 KB |
testcase_02 | AC | 229 ms
61,788 KB |
testcase_03 | RE | - |
testcase_04 | WA | - |
testcase_05 | AC | 142 ms
41,268 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 141 ms
41,672 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 146 ms
41,648 KB |
testcase_12 | AC | 229 ms
61,344 KB |
testcase_13 | AC | 186 ms
52,812 KB |
testcase_14 | AC | 215 ms
58,904 KB |
testcase_15 | AC | 214 ms
59,252 KB |
testcase_16 | AC | 175 ms
48,732 KB |
testcase_17 | AC | 174 ms
49,628 KB |
testcase_18 | AC | 179 ms
52,184 KB |
testcase_19 | AC | 201 ms
59,812 KB |
testcase_20 | AC | 191 ms
55,256 KB |
testcase_21 | AC | 234 ms
62,452 KB |
testcase_22 | AC | 216 ms
62,512 KB |
testcase_23 | AC | 230 ms
62,352 KB |
ソースコード
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; } } }