結果
| 問題 |
No.843 Triple Primes
|
| コンテスト | |
| ユーザー |
Naco
|
| 提出日時 | 2019-07-01 15:20:25 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1,349 ms / 2,000 ms |
| コード長 | 998 bytes |
| コンパイル時間 | 868 ms |
| コンパイル使用メモリ | 69,496 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-20 17:12:26 |
| 合計ジャッジ時間 | 26,515 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 42 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
vector<bool> prime_table(int n){ //素数全列挙
vector<bool> prime(n+1,true);
prime[0]=prime[1]=false;
for(int i=2;i*i<=n;i++){
if(prime[i]!=true) continue;
for(int j=2*i;j<=n;j+=i){
prime[j]=false;
}
}
return prime; //i番目の要素が素数の場合trueを返す
}
int main(){
int N;
cin >> N;
vector<bool> eratos;
eratos=prime_table(N);
vector<long long> res;
for(int i=0;i<=N;i++){
if(eratos[i]==true){
res.push_back(i);
}
}
int ans=0;
for(int i=0;i<res.size();i++){
for(int j=0;j<res.size();j++){
long long k=res[i]*res[i]-res[j];
if(k>=0&&k<=N){
if(eratos[k]==true){
ans++;
//cout << res[i] << res[j] << endl;
}
}
}
}
cout << ans << endl;
}
Naco