結果
問題 | No.843 Triple Primes |
ユーザー | kenta255 |
提出日時 | 2019-12-11 01:16:44 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 378 ms / 2,000 ms |
コード長 | 1,386 bytes |
コンパイル時間 | 2,034 ms |
コンパイル使用メモリ | 208,060 KB |
実行使用メモリ | 5,468 KB |
最終ジャッジ日時 | 2023-09-06 11:48:07 |
合計ジャッジ時間 | 10,841 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 357 ms
5,268 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 3 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 3 ms
4,380 KB |
testcase_07 | AC | 273 ms
4,908 KB |
testcase_08 | AC | 310 ms
5,060 KB |
testcase_09 | AC | 372 ms
5,312 KB |
testcase_10 | AC | 289 ms
5,028 KB |
testcase_11 | AC | 324 ms
5,132 KB |
testcase_12 | AC | 351 ms
5,220 KB |
testcase_13 | AC | 336 ms
5,196 KB |
testcase_14 | AC | 339 ms
5,468 KB |
testcase_15 | AC | 280 ms
4,964 KB |
testcase_16 | AC | 277 ms
4,964 KB |
testcase_17 | AC | 2 ms
4,376 KB |
testcase_18 | AC | 1 ms
4,376 KB |
testcase_19 | AC | 1 ms
4,380 KB |
testcase_20 | AC | 54 ms
4,376 KB |
testcase_21 | AC | 24 ms
4,380 KB |
testcase_22 | AC | 145 ms
4,476 KB |
testcase_23 | AC | 167 ms
4,508 KB |
testcase_24 | AC | 58 ms
4,380 KB |
testcase_25 | AC | 40 ms
4,380 KB |
testcase_26 | AC | 358 ms
5,308 KB |
testcase_27 | AC | 7 ms
4,380 KB |
testcase_28 | AC | 366 ms
5,196 KB |
testcase_29 | AC | 65 ms
4,376 KB |
testcase_30 | AC | 372 ms
5,236 KB |
testcase_31 | AC | 12 ms
4,380 KB |
testcase_32 | AC | 6 ms
4,376 KB |
testcase_33 | AC | 75 ms
4,376 KB |
testcase_34 | AC | 140 ms
4,564 KB |
testcase_35 | AC | 378 ms
5,268 KB |
testcase_36 | AC | 35 ms
4,380 KB |
testcase_37 | AC | 259 ms
4,944 KB |
testcase_38 | AC | 199 ms
4,792 KB |
testcase_39 | AC | 362 ms
5,296 KB |
testcase_40 | AC | 2 ms
4,376 KB |
testcase_41 | AC | 2 ms
4,380 KB |
testcase_42 | AC | 305 ms
5,160 KB |
testcase_43 | AC | 330 ms
5,272 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define P pair<ll,ll> #define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I) #define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I) #define TO(x,t,f) ((x)?(t):(f)) #define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9 #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v x is sorted #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v x is sorted #define NUM(x,v) (POSU(x,v)-POSL(x,v)) //x is sorted #define REV(x) (reverse(x.begin(),x.end())) //reverse ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);} ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);} #define NEXTP(x) next_permutation(x.begin(),x.end()) const ll INF=ll(1e18)+ll(7); const ll MOD=1000000007LL; #define out(a) cout<<fixed<<setprecision((a)) vector<ll> make_p(ll x){ vector<bool> isp(x+1,true); isp[0]=isp[1]=false; for(ll i=2;i*i<=x;i++){ if(isp[i]){ for(ll j=2*i;j<=x;j+=i){ isp[j] = false; } } } vector<ll> res; for(ll i=2;i<=x;i++){ if(isp[i])res.push_back(i); } return res; } int main(){ ll N; cin >> N; auto p = make_p(N); vector<ll> p2; set<ll> sep; for(auto x:p){ ll a = x; sep.insert(a); if(a*a>2*N)continue; p2.push_back(a*a); } int ans = 0; for(auto x:p2){ for(auto y:p){ if(sep.count(x-y))ans++; } } cout << ans << endl; }