結果
問題 | No.407 鴨等素数間隔列の数え上げ |
ユーザー | Grenache |
提出日時 | 2016-08-05 22:40:58 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 218 ms / 1,000 ms |
コード長 | 2,792 bytes |
コンパイル時間 | 4,028 ms |
コンパイル使用メモリ | 79,904 KB |
実行使用メモリ | 69,128 KB |
最終ジャッジ日時 | 2024-12-15 20:24:56 |
合計ジャッジ時間 | 8,715 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 57 ms
50,436 KB |
testcase_01 | AC | 58 ms
50,700 KB |
testcase_02 | AC | 65 ms
51,064 KB |
testcase_03 | AC | 97 ms
54,152 KB |
testcase_04 | AC | 61 ms
50,872 KB |
testcase_05 | AC | 188 ms
66,424 KB |
testcase_06 | AC | 137 ms
61,296 KB |
testcase_07 | AC | 62 ms
50,840 KB |
testcase_08 | AC | 62 ms
50,420 KB |
testcase_09 | AC | 60 ms
50,440 KB |
testcase_10 | AC | 64 ms
50,844 KB |
testcase_11 | AC | 61 ms
50,828 KB |
testcase_12 | AC | 72 ms
51,500 KB |
testcase_13 | AC | 65 ms
51,036 KB |
testcase_14 | AC | 72 ms
51,540 KB |
testcase_15 | AC | 61 ms
50,892 KB |
testcase_16 | AC | 58 ms
51,304 KB |
testcase_17 | AC | 62 ms
50,756 KB |
testcase_18 | AC | 61 ms
50,732 KB |
testcase_19 | AC | 107 ms
54,084 KB |
testcase_20 | AC | 128 ms
56,880 KB |
testcase_21 | AC | 101 ms
53,868 KB |
testcase_22 | AC | 97 ms
54,268 KB |
testcase_23 | AC | 106 ms
56,664 KB |
testcase_24 | AC | 113 ms
56,872 KB |
testcase_25 | AC | 140 ms
59,088 KB |
testcase_26 | AC | 139 ms
59,072 KB |
testcase_27 | AC | 96 ms
53,868 KB |
testcase_28 | AC | 111 ms
56,740 KB |
testcase_29 | AC | 138 ms
59,120 KB |
testcase_30 | AC | 99 ms
54,076 KB |
testcase_31 | AC | 121 ms
58,840 KB |
testcase_32 | AC | 135 ms
59,128 KB |
testcase_33 | AC | 218 ms
69,092 KB |
testcase_34 | AC | 209 ms
69,128 KB |
testcase_35 | AC | 208 ms
66,224 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); } } }