結果
| 問題 |
No.843 Triple Primes
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-06-29 12:22:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,342 bytes |
| コンパイル時間 | 891 ms |
| コンパイル使用メモリ | 96,804 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 05:30:30 |
| 合計ジャッジ時間 | 2,238 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 40 WA * 2 |
ソースコード
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>
#include <list>
using namespace std;
typedef long long Int;
typedef pair<Int,Int> P;
#define rep(i,x) for(Int i = 0; i < (Int)(x); i++)
#define rrep(i,x) for(Int i = ((Int)(x) - 1); i >= 0; i--)
#define _upgrade ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
#define MX 100010
template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}
//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
Int dx[4] = {1,0,-1,0};
Int dy[4] = {0,1,0,-1};
const Int INF = 1001002003004005006ll;
const Int mod = 1e9 + 7;
const double PI = 3.14159265358979323846;
// ****************************************CODE***************************************//
class eratosthenes{
public:
vector<int> prime_n;
bool prime[500001];
eratosthenes(){
fill(prime,prime+500001,true); //素数
prime[0] = prime[1] = false;
for(int i = 2; i < 500001; i++){
if(prime[i] == true){
prime_n.push_back(i);
for(int j = 2; i * j < 500001; j++){
prime[i*j] = false;
}
}
}
}
};
int main(){
eratosthenes p;
int n;
cin >> n;
int ans = 1;
if(n == 1){
cout << 0 << endl;
}
for(int i = 1; i < p.prime_n.size() && p.prime_n[i] <= n; i++){
int r = 2 + p.prime_n[i];
int r_ = floor(sqrt(r));
if(r == r_*r_ && p.prime[r_]){
ans += 2;
}
}
cout << ans << endl;
return 0;
}