結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー btk
提出日時 2016-08-03 15:20:22
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 39 ms / 1,000 ms
コード長 633 bytes
コンパイル時間 1,759 ms
コンパイル使用メモリ 170,928 KB
実行使用メモリ 6,080 KB
最終ジャッジ日時 2024-12-15 14:58:34
合計ジャッジ時間 3,060 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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+(N-2))/(N-1));
    for(auto &p:prime){
        LL len=(N-1)*p;
        res+=max(0ll,L-len+1);
    }
    cout<<res<<endl;

    return 0;
}
0