結果
問題 |
No.843 Triple Primes
|
ユーザー |
👑 |
提出日時 | 2022-04-23 11:19:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 166 ms / 2,000 ms |
コード長 | 676 bytes |
コンパイル時間 | 611 ms |
コンパイル使用メモリ | 72,660 KB |
最終ジャッジ日時 | 2025-01-28 21:04:34 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 42 |
ソースコード
#include <iostream> #include <vector> using namespace std; struct SieveEratos{ vector<bool> t; SieveEratos(int n):t(n+1,true){ t[0] = t[1] = false; for(int i = 2; n >= i; i++){ if(t[i]){ for(int j = i+i; n >= j; j+=i){ t[j] = false; } } } } bool operator[](int x){return t[x];} }; int main(){ long long n;cin>>n; SieveEratos A(n+1); int ans = 0; for(long long i = 0; n >= i; i++){ if(!A[i])continue; for(long long j = 0; n >= j; j++){ if(j*j-i > n)break; if(!A[j] || j*j-i < 0)continue; //cout << i << " " << j << endl; if(A[j*j-i])ans++; } } cout << ans << endl; }