結果
問題 | No.843 Triple Primes |
ユーザー |
![]() |
提出日時 | 2019-06-28 21:44:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 2,088 bytes |
コンパイル時間 | 1,975 ms |
コンパイル使用メモリ | 171,856 KB |
実行使用メモリ | 5,504 KB |
最終ジャッジ日時 | 2024-09-19 13:57:57 |
合計ジャッジ時間 | 3,260 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 42 |
ソースコード
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; 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; } //--------------------------------------------------------------------------------------------------- vector<int> makePrimes(int n) { // [2,n] vector<int> res, pr(n + 1, 1); pr[0] = pr[1] = 0; rep(p, 2, sqrt(n) + 2) if (pr[p]) for (int x = p * 2; x <= n; x += p) pr[x] = 0; rep(p, 2, n + 1) if (pr[p]) res.push_back(p); return res; } vector<bool> makePrimesBool(int n) { // [2,n] vector<bool> pr(n + 1, 1); pr[0] = pr[1] = 0; rep(p, 2, sqrt(n) + 2) if (pr[p]) for (int x = p * 2; x <= n; x += p) pr[x] = 0; return pr; } /*--------------------------------------------------------------------------------------------------- ∧_∧ ∧_∧ (´<_` ) Welcome to My Coding Space! ( ´_ゝ`) / ⌒i @hamayanhamayan / \ | | / / ̄ ̄ ̄ ̄/ | __(__ニつ/ _/ .| .|____ \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, M; //--------------------------------------------------------------------------------------------------- void _main() { cin >> N; M = sqrt(2 * N) + 5; auto vp_n = makePrimes(N); auto vp_m = makePrimes(M); auto vpb_n = makePrimesBool(N); int ans = 0; fore(p, vp_n) fore(r, vp_m) if(p <= N and r <= N) { int q = r * r - p; if (0 <= q and vpb_n[q] and q <= N) ans++; } cout << ans << endl; }