結果
問題 |
No.843 Triple Primes
|
ユーザー |
|
提出日時 | 2019-06-28 22:35:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 624 bytes |
コンパイル時間 | 2,352 ms |
コンパイル使用メモリ | 167,520 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-02 04:57:20 |
合計ジャッジ時間 | 4,644 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 37 WA * 5 |
ソースコード
#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] ) { for ( int p = 2; p <= r*r && p <= n; p++ ) { int q = r*r - p; if ( q > n ) { continue; } if ( arr[p] && arr[q] ) { ans++; } } } } cout << ans-1 << endl; return 0; }