結果
| 問題 |
No.843 Triple Primes
|
| コンテスト | |
| ユーザー |
ldsyb
|
| 提出日時 | 2019-06-28 22:49:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 248 ms / 2,000 ms |
| コード長 | 612 bytes |
| コンパイル時間 | 1,889 ms |
| コンパイル使用メモリ | 169,612 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-19 14:08:48 |
| 合計ジャッジ時間 | 7,864 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 42 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main()
{
int64_t n;
cin >> n;
if (n == 1) {
cout << 0 << endl;
return 0;
}
vector<int64_t> ps;
ps.emplace_back(2);
for (int64_t i = 3; i <= n; i += 2)
{
bool f = true;
for (auto &p : ps)
{
if (i < p * p)
{
break;
}
f &= i % p != 0;
}
if (f)
{
ps.emplace_back(i);
}
}
int64_t ans = 0;
for (auto &x : ps)
{
int64_t r = x * x;
auto itr = lower_bound(ps.begin(), ps.end(), r - 2);
if (itr != ps.end() && (*itr == r - 2))
{
ans++;
}
}
ans *= 2;
ans--;
cout << ans << endl;
return 0;
}
ldsyb