結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー btk
提出日時 2016-08-03 15:18:17
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 66 ms / 1,000 ms
コード長 619 bytes
コンパイル時間 1,659 ms
コンパイル使用メモリ 172,428 KB
実行使用メモリ 10,156 KB
最終ジャッジ日時 2024-12-15 14:55:48
合計ジャッジ時間 3,394 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

struct I{I(){ios::sync_with_stdio(false);cin.tie(0);}}init;

typedef vector<int> V;
typedef long long LL;

V getPrime(LL N){
    N+=3;
    vector<bool> p(N,true);
    p[0]=p[1]=false;
    V res;
    for(int i=2;i*i<=N;i++)
        if(p[i])
            for(int j=i+i;j<N;j+=i)
                p[j]=false;
    for(int i=2;i<N;i++)if(p[i])res.push_back(i);
    return res;
}

int main(){
    LL N,L;cin>>N>>L;
    LL res=0;
    auto prime=getPrime(L);
    for(auto &p:prime){
        LL len=(N-1)*p;
        res+=max(0ll,L-len+1);
    }
    cout<<res<<endl;

    return 0;
}
0