結果

問題 No.843 Triple Primes
ユーザー totori_nyaa
提出日時 2019-07-17 18:52:45
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 655 bytes
コンパイル時間 1,550 ms
コンパイル使用メモリ 169,484 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2024-09-19 14:22:11
合計ジャッジ時間 2,703 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

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

signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);

    ll n;
    cin>>n;

    vector<int> p(n+1,1);
    p[0]=0,p[1]=0;
    vector<int> prime;
    for(int i=2;i<=n;i++){
        if(p[i]){
            for(int j=i+i;j<=n;j+=i){
                p[j]=0;
            }
            prime.push_back(i);
        }
    }
    ll ans=0;
    for(int q=0;q<prime.size();q++){
        if(prime[q]*prime[q]>2*n) break;
        for(int r=0;r<prime.size();r++){
            ll t=prime[q]*prime[q]-prime[r];
            if(t>0 && t<=n && p[t]) ans++;
        }
    }
    cout<<ans<<endl;
    
}
0