結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー crazybbb3crazybbb3
提出日時 2016-11-27 16:58:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 149 ms / 1,000 ms
コード長 2,284 bytes
コンパイル時間 4,242 ms
コンパイル使用メモリ 73,708 KB
実行使用メモリ 81,656 KB
最終ジャッジ日時 2023-08-22 06:41:55
合計ジャッジ時間 10,959 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
81,412 KB
testcase_01 AC 131 ms
81,444 KB
testcase_02 AC 137 ms
81,548 KB
testcase_03 AC 140 ms
81,656 KB
testcase_04 AC 129 ms
81,384 KB
testcase_05 AC 135 ms
81,512 KB
testcase_06 AC 140 ms
81,360 KB
testcase_07 AC 140 ms
81,276 KB
testcase_08 AC 130 ms
81,376 KB
testcase_09 AC 137 ms
81,436 KB
testcase_10 AC 126 ms
81,300 KB
testcase_11 AC 136 ms
81,204 KB
testcase_12 AC 137 ms
81,544 KB
testcase_13 AC 133 ms
81,220 KB
testcase_14 AC 125 ms
81,264 KB
testcase_15 AC 138 ms
81,148 KB
testcase_16 AC 142 ms
81,448 KB
testcase_17 AC 137 ms
81,248 KB
testcase_18 AC 136 ms
81,256 KB
testcase_19 AC 128 ms
81,300 KB
testcase_20 AC 144 ms
81,296 KB
testcase_21 AC 133 ms
81,348 KB
testcase_22 AC 133 ms
81,412 KB
testcase_23 AC 140 ms
81,264 KB
testcase_24 AC 121 ms
81,408 KB
testcase_25 AC 126 ms
81,252 KB
testcase_26 AC 130 ms
81,456 KB
testcase_27 AC 135 ms
81,280 KB
testcase_28 AC 133 ms
81,296 KB
testcase_29 AC 139 ms
81,192 KB
testcase_30 AC 149 ms
81,356 KB
testcase_31 AC 128 ms
81,584 KB
testcase_32 AC 131 ms
81,288 KB
testcase_33 AC 149 ms
81,368 KB
testcase_34 AC 137 ms
81,296 KB
testcase_35 AC 146 ms
81,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        long n = nl();
        long l = nl();

        cprime();

        long ans = 0;

        for (int i = 0; i < 1000000; i++) {
            if (prime[i] * (n - 1) > l) {
                break;
            }

            ans += l - prime[i] * (n - 1) + 1;
        }

        out.println(ans);
    }

    int prime_max = 6000000;
    int pidx = 0;
    int[] prime = new int[1000000];
    int[] divp = new int[prime_max];

    void cprime() {
        for (int i = 2; i < prime_max; i++) {
            if (divp[i] == 0) {
                prime[pidx++] = i;
                for (long j = (long) i * i; j < prime_max; j += i) {
                    divp[(int) j] = i;
                }
            }
        }
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}
0