結果

問題 No.843 Triple Primes
ユーザー closeknclosekn
提出日時 2019-06-28 22:35:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 624 bytes
コンパイル時間 1,476 ms
コンパイル使用メモリ 164,692 KB
実行使用メモリ 5,472 KB
最終ジャッジ日時 2023-09-14 22:20:15
合計ジャッジ時間 4,773 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 88 ms
5,292 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 66 ms
4,952 KB
testcase_08 AC 73 ms
5,048 KB
testcase_09 AC 87 ms
5,332 KB
testcase_10 AC 69 ms
4,972 KB
testcase_11 AC 78 ms
5,180 KB
testcase_12 AC 85 ms
5,356 KB
testcase_13 AC 82 ms
5,304 KB
testcase_14 AC 82 ms
5,184 KB
testcase_15 AC 67 ms
4,928 KB
testcase_16 AC 68 ms
5,016 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 16 ms
4,380 KB
testcase_21 AC 8 ms
4,376 KB
testcase_22 AC 39 ms
4,416 KB
testcase_23 AC 42 ms
4,468 KB
testcase_24 AC 17 ms
4,376 KB
testcase_25 AC 12 ms
4,376 KB
testcase_26 AC 87 ms
5,280 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 83 ms
5,212 KB
testcase_29 AC 18 ms
4,380 KB
testcase_30 AC 85 ms
5,436 KB
testcase_31 AC 5 ms
4,376 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 21 ms
4,376 KB
testcase_34 AC 35 ms
4,448 KB
testcase_35 AC 88 ms
5,472 KB
testcase_36 AC 10 ms
4,376 KB
testcase_37 AC 62 ms
4,908 KB
testcase_38 AC 50 ms
4,780 KB
testcase_39 AC 83 ms
5,216 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 72 ms
5,084 KB
testcase_43 AC 78 ms
5,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0