結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー dnk
提出日時 2016-08-05 22:56:34
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 58 ms / 1,000 ms
コード長 533 bytes
コンパイル時間 1,223 ms
コンパイル使用メモリ 159,308 KB
実行使用メモリ 13,300 KB
最終ジャッジ日時 2024-12-15 21:52:51
合計ジャッジ時間 4,121 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

const int N = 1e7;
bool isPrime[N + 1];

int main() {
    for (int i = 2; i <= N; ++i) isPrime[i] = true;
    for (int i = 2; i * i <= N; ++i) if (isPrime[i]) {
        for (int j = i * i; j <= N; j += i) if (isPrime[j]) {
            isPrime[j] = false;
        }
    }
    int n; cin >> n;
    int l; cin >> l;
    long long res = 0;
    for (int d = 1; 1LL * (n - 1) * d <= l; ++d) if (isPrime[d]) {
        res += l - (n - 1) * d + 1;
    }
    cout << res << '\n';
    return 0;
}
0