結果
問題 | No.843 Triple Primes |
ユーザー | beet |
提出日時 | 2019-06-28 21:27:53 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 465 ms / 2,000 ms |
コード長 | 688 bytes |
コンパイル時間 | 1,783 ms |
コンパイル使用メモリ | 196,832 KB |
最終ジャッジ日時 | 2025-01-07 05:22:31 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 42 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} Int isprime(Int x){ if(x<=1) return 0; for(Int i=2;i*i<=x;i++) if(x%i==0) return 0; return 1; } //INSERT ABOVE HERE signed main(){ Int n; cin>>n; vector<Int> ps; for(Int i=2;i<=n;i++) if(isprime(i)) ps.emplace_back(i); const Int MAX = 1e6+10; vector<Int> qs; Int ans=0; for(Int r:ps){ if(r>MAX/r+1) break; for(Int p:ps){ if(binary_search(ps.begin(),ps.end(),r*r-p)) ans++; } } cout<<ans<<endl; return 0; }