結果
問題 | No.843 Triple Primes |
ユーザー |
![]() |
提出日時 | 2019-06-28 22:58:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 706 bytes |
コンパイル時間 | 642 ms |
コンパイル使用メモリ | 74,584 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-02 05:05:43 |
合計ジャッジ時間 | 7,333 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 WA * 4 |
ソースコード
#include <algorithm> #include <iostream> #include <vector> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; bool is_prime(int64_t x) { for (int64_t y = 2; y * y <= x; y++) { if (x % y == 0) return false; } return true; } int main() { int n; cin >> n; vector<int64_t> primes; for (int64_t x = 2; x <= n; x++) { if (is_prime(x)) primes.push_back(x); } vector<int> exists(n + 1, false); for (auto p : primes) { exists[p] = true; } int ans = 0; for (auto r : primes) { if (r * r > n) break; for (auto p : primes) { auto q = r * r - p; if (q >= 0 and exists[q]) { ans += 1; } } } cout << ans << endl; return 0; }