結果
問題 | No.843 Triple Primes |
ユーザー | Suu0313 |
提出日時 | 2020-11-02 15:13:46 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 5,489 bytes |
コンパイル時間 | 2,066 ms |
コンパイル使用メモリ | 209,828 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-22 06:15:11 |
合計ジャッジ時間 | 8,488 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | AC | 2 ms
5,376 KB |
testcase_42 | RE | - |
testcase_43 | RE | - |
ソースコード
#include <bits/stdc++.h> using namespace std; //conversion //------------------------------------------ inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} //math //------------------------------------------- template<class T> inline T sqr(T x) {return x*x;} //typedef //------------------------------------------ typedef long long LL; typedef pair<int, int> PII; typedef pair<LL,LL> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<bool> VB; typedef vector<VB> VVB; typedef vector<double> VD; typedef vector<VD> VVD; typedef vector<string> VS; typedef vector<VS> VVS; typedef vector<char> VC; typedef vector<VC> VVC; typedef vector<PII> VPII; typedef vector<PLL> VPLL; typedef priority_queue<int> PQGI; //大きい順 typedef priority_queue<int, VI, greater<int>> PQLI; typedef priority_queue<PII> PQGP; typedef priority_queue<PII, VPII, greater<PII>> PQLP; //priority_queue<T,vector<T>,decltype(f)> pq{f}; //container util //------------------------------------------ #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define EB emplace_back #define EF emplace_front #define PB push_back #define PF push_front #define POB pop_back #define POF pop_front #define MP make_pair #define SZ(a) (int)((a).size()) #define SQ(a) ((a)*(a)) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) #define SORTR(c) sort((c).rbegin(), (c).rend()) #define LB lower_bound #define UB upper_bound #define NEXP(a) next_permutation((a).begin(),(a).end()) #define FI first #define SE second #define Vmin(a) *min_element((a).begin(),(a).end()) #define Vmax(a) *max_element((a).begin(),(a).end()) //repetition //------------------------------------------ #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define FORR(i,a,b) for(int i = (b-1);i>=(a);i--) #define REPR(i,n) FORR(i,0,n) #define CFOR(i,a,b) for(int i=(a);i<=(b);++i) #define CREP(i,n) CFOR(i,0,n) #define CFORR(i,a,b) for(int i = (b);i>=(a);i--) #define CREPR(i,n) CFORR(i,0,n) #define BFOR(bit,a,b) for(int bit = (a); bit < (1ll<<(b)); ++bit) #define BREP(bit,n) BFOR(bit,0,n) //constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = INT_MAX/2; const LL LINF = LLONG_MAX/3; const int RINF = INT_MIN/2; const LL RLINF = LLONG_MIN/3; const LL MOD = 1e9+7; const LL MODD = 998244353; const int MAX = 510000; inline bool Eq(double a, double b) { return fabs(b - a) < EPS; } //other //------------------------------------------- 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 (b<a) { a=b; return 1; } return 0; } #define ISIN(x,l,r) ((l) <= (x) && (x) < (r)) #define CEIL(x,y) (((x)+(y)-1)/(y)) inline LL toLL(string s) {LL v; istringstream sin(s);sin>>v;return v;} template<typename T> T Vsum(vector<T> &v){T res(0);for(auto&&x:v) res += x; return res; } template<typename T> T Vgcd(vector<T> &v){T res(0);for(auto&&x:v) res=gcd(res,x); return res; } template<typename T> T Vlcm(vector<T> &v){T res(1);for(auto&&x:v) res=lcm(res,x); return res; } #define COUT(x) cout << (x) << endl #define COUT2(x,y) cout << (x) << " " << (y) << endl #define COUT3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl #define BC(x) __builtin_popcountll(x) VI dx = {1,0,-1,0,1,1,-1,-1}; VI dy = {0,1,0,-1,1,-1,1,-1}; template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template< typename T1, typename T2 > ostream &operator<<(ostream &os, const pair< T1, T2 >& p) { os << p.first << " " << p.second; return os; } template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; } template< typename T > ostream &operator<<(ostream &os, const vector< T > &v) { for(int i = 0; i < SZ(v); i++) { os << v[i] << (i + 1 != SZ(v) ? " " : ""); } return os; } template<typename T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);} template<typename... Ts> auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v(ts...))>(a,make_v(ts...)); } struct FastFactor{ int n; VI min_factor; FastFactor(int _n):n(_n+1),min_factor(_n+1){ iota(ALL(min_factor),0); for(int i = 2; i*i < n; ++i){ if(min_factor.at(i) < i) continue; for(int j = i*i; j < n; j += i){ if(min_factor.at(j) == j) min_factor.at(j) = i; } } } map<int,int> factor(int a){ map<int,int> res; while(a > 1){ res[min_factor.at(a)]++; a /= min_factor.at(a); } return res; } bool isPrime(int p){ if(p<=1) return false; return p == min_factor.at(p); } VI prime_table(){ VI res; CREP(i,n){ if(isPrime(i)) res.PB(i); } return res; } }; int main() { // cin.tie(0); // ios::sync_with_stdio(false); cout << fixed << setprecision(12); int N; cin >> N; if(N == 1){ COUT(0); return 0; } FastFactor ff(N); VI pt = ff.prime_table(); int ans = 0; for(auto p : pt){ if(p==2)continue; LL q = (LL)p*p-2; if(ff.isPrime(q)) ans++; } ans *= 2; ans++; COUT(ans); return 0; }