結果
| 問題 |
No.843 Triple Primes
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-06-28 22:47:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 62 ms / 2,000 ms |
| コード長 | 652 bytes |
| コンパイル時間 | 3,566 ms |
| コンパイル使用メモリ | 166,712 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-19 14:08:27 |
| 合計ジャッジ時間 | 3,649 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 42 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
void Eratosthenes(int arr[], int n) {
for(int i = 0; i <= n; i++){
arr[i] = 1;
}
for(int i = 2; i < sqrt(n); i++){
if(arr[i]){
for(int j = 0; i * (j + 2) <= n; j++){
arr[i *(j + 2)] = 0;
}
}
}
}
int main() {
int n;
cin >> n;
int arr[n+1];
int ans = 0;
Eratosthenes(arr, n);
for ( int r = 2; r*r <= 2*n; r++ ) {
if ( arr[r] ) {
int p = 2;
int q = r*r - p;
if ( q > n ) { p += q-n; q = n; }
while ( p <= n && q >= 2 ) {
if ( arr[p] && arr[q] ) { ans++; }
p++;
q--;
}
}
}
cout << ans << endl;
return 0;
}