結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー kimiyukikimiyuki
提出日時 2016-10-19 17:20:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 1,000 ms
コード長 791 bytes
コンパイル時間 988 ms
コンパイル使用メモリ 71,596 KB
実行使用メモリ 9,040 KB
最終ジャッジ日時 2023-08-22 06:37:39
合計ジャッジ時間 3,510 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 60 ms
8,880 KB
testcase_06 AC 32 ms
5,896 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 7 ms
4,380 KB
testcase_20 AC 19 ms
4,576 KB
testcase_21 AC 9 ms
4,384 KB
testcase_22 AC 8 ms
4,384 KB
testcase_23 AC 14 ms
4,384 KB
testcase_24 AC 19 ms
4,512 KB
testcase_25 AC 31 ms
5,852 KB
testcase_26 AC 31 ms
5,716 KB
testcase_27 AC 6 ms
4,380 KB
testcase_28 AC 15 ms
4,380 KB
testcase_29 AC 30 ms
5,724 KB
testcase_30 AC 7 ms
4,380 KB
testcase_31 AC 25 ms
5,616 KB
testcase_32 AC 31 ms
5,852 KB
testcase_33 AC 64 ms
9,040 KB
testcase_34 AC 64 ms
8,644 KB
testcase_35 AC 57 ms
8,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;
vector<int> sieve_of_eratosthenes(int n) { // enumerate primes in [2,n] with O(n log log n)
    vector<bool> is_prime(n+1, true);
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i*i <= n; ++i)
        if (is_prime[i])
            for (int k = i+i; k <= n; k += i)
                is_prime[k] = false;
    vector<int> primes;
    for (int i = 2; i <= n; ++i)
        if (is_prime[i])
            primes.push_back(i);
    return primes;
}
int main() {
    int n, l; cin >> n >> l;
    vector<int> primes = sieve_of_eratosthenes(l);
    ll ans = 0;
    for (int d : primes) {
        int k = l - d * (n-1) + 1;
        if (k < 0) break;
        ans += k;
    }
    cout << ans << endl;
    return 0;
}
0