結果
| 問題 |
No.843 Triple Primes
|
| コンテスト | |
| ユーザー |
MiyanagaTeru
|
| 提出日時 | 2019-09-29 21:12:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,041 bytes |
| コンパイル時間 | 1,860 ms |
| コンパイル使用メモリ | 191,232 KB |
| 最終ジャッジ日時 | 2025-01-07 19:53:47 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 36 WA * 6 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define MAX_N 1000000
int prime[MAX_N]; //i番目の素数
bool is_prime[MAX_N+1]; //is_prime[i]==true->iはprime
//n以下の素数の数を返す
void sieve(int n) {
int p = 0;
rep(i,n+1) is_prime[i] = true;
is_prime[0] = is_prime[1] = false;
rep2(i,n+1) {
if(is_prime[i]) {
prime[p++] = i;
for(int j = 2 * i; j<= n; j+= i) is_prime[j] = false;
}
}
return ;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N; cin >> N;
sieve(500005);
int cnt = 0;
for(int i = 2; i <= N; i++) {
if(!is_prime[i]) continue;
for(int j = 2; j * j <= N; j++) {
if(!is_prime[j]) continue;
if(2 + i == j * j) cnt++;
}
}
cout << 2 * cnt - 1 << endl;
return 0;
}
MiyanagaTeru