結果
問題 | No.407 鴨等素数間隔列の数え上げ |
ユーザー | Grenache |
提出日時 | 2016-08-05 22:40:58 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 220 ms / 1,000 ms |
コード長 | 2,792 bytes |
コンパイル時間 | 4,881 ms |
コンパイル使用メモリ | 76,072 KB |
実行使用メモリ | 70,264 KB |
最終ジャッジ日時 | 2023-08-22 03:10:56 |
合計ジャッジ時間 | 10,240 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 59 ms
50,268 KB |
testcase_01 | AC | 57 ms
50,136 KB |
testcase_02 | AC | 58 ms
50,312 KB |
testcase_03 | AC | 100 ms
54,420 KB |
testcase_04 | AC | 58 ms
50,264 KB |
testcase_05 | AC | 196 ms
67,368 KB |
testcase_06 | AC | 138 ms
61,124 KB |
testcase_07 | AC | 56 ms
50,268 KB |
testcase_08 | AC | 57 ms
50,028 KB |
testcase_09 | AC | 57 ms
50,104 KB |
testcase_10 | AC | 57 ms
50,312 KB |
testcase_11 | AC | 56 ms
48,092 KB |
testcase_12 | AC | 69 ms
51,504 KB |
testcase_13 | AC | 64 ms
51,076 KB |
testcase_14 | AC | 66 ms
51,172 KB |
testcase_15 | AC | 60 ms
50,152 KB |
testcase_16 | AC | 60 ms
50,224 KB |
testcase_17 | AC | 61 ms
50,460 KB |
testcase_18 | AC | 60 ms
50,332 KB |
testcase_19 | AC | 103 ms
54,220 KB |
testcase_20 | AC | 127 ms
56,344 KB |
testcase_21 | AC | 100 ms
54,060 KB |
testcase_22 | AC | 96 ms
54,284 KB |
testcase_23 | AC | 106 ms
56,576 KB |
testcase_24 | AC | 113 ms
56,332 KB |
testcase_25 | AC | 148 ms
57,232 KB |
testcase_26 | AC | 131 ms
58,884 KB |
testcase_27 | AC | 94 ms
54,124 KB |
testcase_28 | AC | 106 ms
56,568 KB |
testcase_29 | AC | 129 ms
58,812 KB |
testcase_30 | AC | 95 ms
54,724 KB |
testcase_31 | AC | 123 ms
56,812 KB |
testcase_32 | AC | 141 ms
58,816 KB |
testcase_33 | AC | 220 ms
70,056 KB |
testcase_34 | AC | 220 ms
70,264 KB |
testcase_35 | AC | 216 ms
67,912 KB |
ソースコード
import java.io.*; import java.util.*; public class Main_yukicoder407 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); int n = sc.nextInt(); int l = sc.nextInt(); Prime p = new Prime(l); List<Integer> primes = p.getPrimeList(); long ret = 0; for (int i : primes) { long tmp = (long)i * (n - 1); if (tmp > l) { break; } ret += l - tmp + 1; } pr.println(ret); pr.close(); sc.close(); } @SuppressWarnings("unused") private static class Prime { private int n; private List<Integer> primes; private BitSet p; Prime(int n) { this.n = n; p = new BitSet(n / 2); int m = (int)Math.sqrt(n); for (int i = 1; i <= m; i++) { if (p.get(i - 1)) { continue; } for (int j = 2 * i * (i + 1); 2 * j + 1 <= n; j += 2 * i + 1) { p.set(j - 1); } } } boolean isPrime(int n) { if (n == 2) { return true; } if (n == 1 || (n & 0x1) == 0) { return false; } return !p.get(n / 2 - 1); } List<Integer> getPrimeList() { if (primes != null) { return primes; } primes = new ArrayList<>(); if (n >= 2) { primes.add(2); for (int i = 1; 2 * i + 1 <= n; i++) { if (!p.get(i - 1)) { primes.add(2 * i + 1); } } } return primes; } private static boolean isPrime(long n) { if (n == 2) { return true; } if (n == 1 || (n & 0x1) == 0) { return false; } for (long i = 3; i * i <= n; i += 2) { if (n % i == 0) { return false; } } return true; } } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator<String> it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { // it = Arrays.asList(br.readLine().split(" ")).iterator(); it = Arrays.asList(br.readLine().split("\\p{javaWhitespace}+")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }