結果
| 問題 |
No.843 Triple Primes
|
| コンテスト | |
| ユーザー |
ikd
|
| 提出日時 | 2019-06-28 23:00:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 259 ms / 2,000 ms |
| コード長 | 721 bytes |
| コンパイル時間 | 597 ms |
| コンパイル使用メモリ | 73,904 KB |
| 実行使用メモリ | 5,708 KB |
| 最終ジャッジ日時 | 2024-09-19 14:09:00 |
| 合計ジャッジ時間 | 6,535 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 42 |
ソースコード
#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 * 2) break;
for (auto p : primes) {
auto q = r * r - p;
if (q >= 0 and q <= n and exists[q]) { ans += 1; }
}
}
cout << ans << endl;
return 0;
}
ikd