結果

問題 No.843 Triple Primes
ユーザー aaaaaaiu
提出日時 2019-08-22 21:28:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 614 bytes
コンパイル時間 1,850 ms
コンパイル使用メモリ 194,124 KB
最終ジャッジ日時 2025-01-07 14:38:46
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 RE * 1
other AC * 4 WA * 4 RE * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int n;
    cin>>n;
    bool isp[n+1];
    fill(isp,isp+n+1,true);
    isp[0]=isp[1]=false;
    vector<int> ps;
    for (int i=2;i<=n;i++) {
        if (isp[i]) {
            ps.push_back(i);
            for (int j=i+i;j<=n;j+=i)
                isp[j]=false;
        }
    }
    int ans=0;
    for (int r:ps) {
        if (r*r>2*n)
            break;
        for (int p:ps) {
            int q=r*r-p;
            if (q<0) break;
            if (isp[q])
                ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}
0