結果

問題 No.732 3PrimeCounting
ユーザー WarToksWarToks
提出日時 2018-09-17 16:39:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,013 bytes
コンパイル時間 1,702 ms
コンパイル使用メモリ 171,224 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-09-25 09:30:07
合計ジャッジ時間 51,709 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,756 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 8 ms
4,376 KB
testcase_22 AC 7 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 20 ms
4,380 KB
testcase_26 AC 11 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 5 ms
4,376 KB
testcase_30 AC 5 ms
4,376 KB
testcase_31 AC 8 ms
4,380 KB
testcase_32 AC 13 ms
4,376 KB
testcase_33 AC 13 ms
4,380 KB
testcase_34 AC 14 ms
4,376 KB
testcase_35 AC 9 ms
4,376 KB
testcase_36 AC 9 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 10 ms
4,376 KB
testcase_40 AC 9 ms
4,380 KB
testcase_41 AC 8 ms
4,380 KB
testcase_42 AC 8 ms
4,380 KB
testcase_43 AC 6 ms
4,380 KB
testcase_44 AC 6 ms
4,376 KB
testcase_45 AC 3 ms
4,380 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 4 ms
4,376 KB
testcase_48 AC 22 ms
4,376 KB
testcase_49 AC 22 ms
4,380 KB
testcase_50 AC 7 ms
4,376 KB
testcase_51 AC 7 ms
4,376 KB
testcase_52 AC 3 ms
4,376 KB
testcase_53 AC 75 ms
4,376 KB
testcase_54 AC 1,678 ms
4,380 KB
testcase_55 AC 1,676 ms
4,376 KB
testcase_56 AC 1,679 ms
4,376 KB
testcase_57 AC 272 ms
4,380 KB
testcase_58 AC 271 ms
4,376 KB
testcase_59 AC 85 ms
4,376 KB
testcase_60 AC 434 ms
4,380 KB
testcase_61 AC 434 ms
4,376 KB
testcase_62 AC 2,257 ms
4,376 KB
testcase_63 AC 885 ms
4,376 KB
testcase_64 AC 583 ms
4,376 KB
testcase_65 AC 583 ms
4,384 KB
testcase_66 AC 2 ms
4,380 KB
testcase_67 AC 2 ms
4,376 KB
testcase_68 AC 1,929 ms
4,376 KB
testcase_69 AC 1,930 ms
4,376 KB
testcase_70 AC 1,707 ms
4,380 KB
testcase_71 AC 1,708 ms
4,380 KB
testcase_72 AC 822 ms
4,376 KB
testcase_73 TLE -
testcase_74 TLE -
testcase_75 AC 18 ms
4,380 KB
testcase_76 AC 1,873 ms
4,376 KB
testcase_77 AC 299 ms
4,380 KB
testcase_78 AC 2,871 ms
4,380 KB
testcase_79 AC 1,966 ms
4,376 KB
testcase_80 AC 2,531 ms
4,376 KB
testcase_81 AC 1,729 ms
4,380 KB
testcase_82 AC 2 ms
4,380 KB
testcase_83 AC 286 ms
4,380 KB
testcase_84 AC 329 ms
4,376 KB
testcase_85 AC 1,422 ms
4,380 KB
testcase_86 AC 2,599 ms
4,380 KB
testcase_87 TLE -
testcase_88 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
  int n;
  scanf("%d",&n);
  vector<bool> isPrime(3 * n + 1,true);
  for(int i = 2;i <= 3 * n;i++){
    if(isPrime.at(i)){
      for(int j = 2 * i;j <= 3 * n;j += i){
        isPrime.at(j) = false;
      }
    }
  }
  vector <int> Primes;
  for(int i = 3;i <= n;i++){
    if(isPrime.at(i)){
      Primes.push_back(i);
    }
  }
  int size = Primes.size();
  vector <int> GET(2 * Primes.back() + 1,0);
  long long int ans = 0;
  long long int minus = 0;
  for(int i = 0;i < size - 1;i++){
    int U = Primes.at(i);
    for(int j = i + 1;j < size;j++){
      int V = Primes.at(j);
      GET.at(U + V)++;
      if(isPrime.at(U + 2 * V)) minus++;
      if(isPrime.at(2 * U + V)) minus++;
    }
  }

  for(int i = 0;i < size;i++){
    int U = Primes.at(i);
    for(int j = 4; j <= 2 * Primes.back();j +=2){
      if(isPrime.at(U + j) && GET.at(j) > 0){
        ans += GET.at(j);
      }
    }
  }
  ans = (ans - minus) / 3;
  cout << ans << endl;
  return 0;
}
0