結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー takeya_okinotakeya_okino
提出日時 2019-09-07 03:24:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 231 ms / 1,000 ms
コード長 759 bytes
コンパイル時間 2,597 ms
コンパイル使用メモリ 74,820 KB
実行使用メモリ 74,940 KB
最終ジャッジ日時 2023-09-07 08:41:02
合計ジャッジ時間 9,377 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,984 KB
testcase_01 AC 123 ms
55,784 KB
testcase_02 AC 122 ms
55,816 KB
testcase_03 AC 143 ms
56,000 KB
testcase_04 AC 121 ms
55,704 KB
testcase_05 AC 120 ms
55,476 KB
testcase_06 AC 122 ms
55,744 KB
testcase_07 AC 121 ms
55,708 KB
testcase_08 AC 124 ms
55,488 KB
testcase_09 AC 125 ms
55,664 KB
testcase_10 AC 122 ms
55,668 KB
testcase_11 AC 122 ms
55,864 KB
testcase_12 AC 120 ms
53,908 KB
testcase_13 AC 125 ms
55,720 KB
testcase_14 AC 133 ms
53,580 KB
testcase_15 AC 137 ms
55,632 KB
testcase_16 AC 133 ms
55,660 KB
testcase_17 AC 132 ms
55,688 KB
testcase_18 AC 136 ms
55,724 KB
testcase_19 AC 157 ms
57,920 KB
testcase_20 AC 171 ms
60,252 KB
testcase_21 AC 132 ms
55,844 KB
testcase_22 AC 130 ms
55,680 KB
testcase_23 AC 129 ms
55,620 KB
testcase_24 AC 130 ms
56,028 KB
testcase_25 AC 187 ms
62,604 KB
testcase_26 AC 132 ms
55,688 KB
testcase_27 AC 140 ms
55,596 KB
testcase_28 AC 129 ms
55,712 KB
testcase_29 AC 130 ms
56,064 KB
testcase_30 AC 131 ms
55,768 KB
testcase_31 AC 132 ms
55,860 KB
testcase_32 AC 169 ms
60,000 KB
testcase_33 AC 228 ms
74,940 KB
testcase_34 AC 231 ms
74,924 KB
testcase_35 AC 179 ms
62,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long l = sc.nextLong();
    int t = (int)l / (n - 1);
    ArrayList<Long> prime = new ArrayList<Long>();
    boolean[] is_prime = new boolean[t + 1];
    for(int i = 0; i <= t; i++) is_prime[i] = true;
    is_prime[0] = false;
    if(t >= 1) is_prime[1] = false;
    for(int i = 2; i <= t; i++) {
      if(is_prime[i]) {
        prime.add((long)i);
        for(int j = 2 * i; j <= t; j += i) is_prime[j] = false;
      }
    }
    long ans = 0;
    for(int i = 0; i < prime.size(); i++) {
      long p = prime.get(i);
      ans += (l + 1 - p * (long)(n - 1));
    }
    System.out.println(ans);    
  }
}
0