結果
| 問題 |
No.843 Triple Primes
|
| コンテスト | |
| ユーザー |
icun
|
| 提出日時 | 2019-08-30 17:13:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,028 bytes |
| コンパイル時間 | 1,528 ms |
| コンパイル使用メモリ | 166,416 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-21 13:30:39 |
| 合計ジャッジ時間 | 2,851 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 42 |
ソースコード
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;
bool isPrime(int n) {
if(n < 2)
return false;
else if(n == 2)
return true;
else if(n % 2 == 0)
return false;
double sq = sqrt(n);
for(int i = 3; i <= sq; i += 2) {
if(n % i == 0) return false;
}
return true;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll ans = 1;
if(n == 1) {
cout << 0 << endl;
return 0;
}
for(ll i = 3; i < n; i += 2) {
if(i * i - 2 > n) continue;
if(!isPrime(i)) continue;
if(isPrime(i * i - 2)) ans += 2;
}
cout << ans << endl;
}
icun