結果
問題 | No.843 Triple Primes |
ユーザー | Kichico |
提出日時 | 2022-05-12 01:45:42 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,021 bytes |
コンパイル時間 | 2,514 ms |
コンパイル使用メモリ | 213,496 KB |
実行使用メモリ | 13,884 KB |
最終ジャッジ日時 | 2024-07-19 12:39:36 |
合計ジャッジ時間 | 6,771 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | TLE | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | TLE | - |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 1 ms
5,376 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | TLE | - |
testcase_27 | WA | - |
testcase_28 | TLE | - |
testcase_29 | WA | - |
testcase_30 | TLE | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | TLE | - |
testcase_36 | WA | - |
testcase_37 | TLE | - |
testcase_38 | WA | - |
testcase_39 | TLE | - |
testcase_40 | AC | 2 ms
5,376 KB |
testcase_41 | AC | 2 ms
5,376 KB |
testcase_42 | TLE | - |
testcase_43 | TLE | - |
ソースコード
#include "bits/stdc++.h" using namespace std; using ll = int64_t; using ld = long double; using ull = unsigned long long; #define ALL(x) x.begin(),x.end() #define rep(iter,from,to) for(ll iter=from;iter<to;++iter) #define fore(variable,container) for(auto& variable:container) #define forc(variable,container) for(auto& variable:container) cout<<variable<<endl; const ll MOD = 1e9 + 7; const ll INF = 1e17; const vector<ll> dx{ 1,0,-1,0 }, dy{ 0,1,0,-1 }; //####################################################################### void op(vector<ll> vec) { ll size = (ll)vec.size(); for (ll i = 0; i < size - 1; ++i) cout << vec[i] << " "; cout << vec.back() << endl; } void op(vector<vector<ll>> vec) { ll height = (ll)vec.size(); ll width = (ll)vec[0].size(); for (ll i = 0; i < height; ++i) { for (ll j = 0; j < width - 1; ++j) cout << vec[i][j] << " "; cout << vec[i].back() << endl; } } void twoText(bool identifier, string outTrue, string outFalse) { if (identifier) cout << outTrue << endl; else cout << outFalse << endl; } void twoText(bool identifier) { if (identifier) cout << "Yes" << endl; else cout << "No" << endl; } template <class T> T vecsum(vector<T>& vec) { return accumulate(ALL(vec), (T)0); } template<class T, ll> T vecsum(vector<T>& vec, ll K) { ll ret = 0; rep(i, 0, K) ret += vec[i]; return ret; } template <class T> struct grid { vector<vector<T>> field; grid(ll height, ll width) { field = vector<vector<T>>(height, vector<T>(width, (T)0)); } void input() { rep(i, 0, field.size()) rep(j, 0, field[i].size()) cin >> field[i][j]; } }; //######################################################################### bool isPrime(ll Num) { ll root = sqrt(Num); if (Num == 0 || Num == 1) return false; for (ll i = 2; i <= root; ++i) if (Num % i == 0) return false; return true; } vector<ll> enumeratePrime(ll maxx) { vector<bool> notp(maxx + 1, false); vector<ll> ret; rep(i, 2, maxx) { if (notp[i]) continue; if (isPrime(i)) ret.emplace_back(i); ll init = 1; while (init * i <= maxx) { notp[init * i] = true; init++; } } return ret; } void solve() { ll N; cin >> N; auto primes = enumeratePrime(N); unordered_set<ll> primeSet; fore(x, primes) primeSet.emplace(x); ll ans = 0; if (N == 2) { cout << 1 << endl; return; } fore(r, primes) { if (r * r > 2 * N) break; rep(i, 0, primes.size()) { ll p = primes[i]; if (p > r * r / 2) break; ll q = r * r - p; cout << p << " " << endl; if (primeSet.find(q) != primeSet.end()) { if (p == q) ans++; else ans += 2; } } } cout << ans << endl; } int main(void) { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); solve(); }