結果

問題 No.843 Triple Primes
ユーザー beetbeet
提出日時 2019-06-28 21:27:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 447 ms / 2,000 ms
コード長 688 bytes
コンパイル時間 2,259 ms
コンパイル使用メモリ 204,684 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 17:28:16
合計ジャッジ時間 12,588 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 447 ms
4,348 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 5 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 6 ms
4,348 KB
testcase_07 AC 340 ms
4,348 KB
testcase_08 AC 379 ms
4,348 KB
testcase_09 AC 445 ms
4,348 KB
testcase_10 AC 358 ms
4,348 KB
testcase_11 AC 402 ms
4,348 KB
testcase_12 AC 432 ms
4,348 KB
testcase_13 AC 417 ms
4,348 KB
testcase_14 AC 416 ms
4,348 KB
testcase_15 AC 348 ms
4,348 KB
testcase_16 AC 354 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 89 ms
4,348 KB
testcase_21 AC 43 ms
4,348 KB
testcase_22 AC 215 ms
4,348 KB
testcase_23 AC 223 ms
4,348 KB
testcase_24 AC 94 ms
4,348 KB
testcase_25 AC 69 ms
4,348 KB
testcase_26 AC 442 ms
4,348 KB
testcase_27 AC 15 ms
4,348 KB
testcase_28 AC 422 ms
4,348 KB
testcase_29 AC 103 ms
4,348 KB
testcase_30 AC 435 ms
4,348 KB
testcase_31 AC 26 ms
4,348 KB
testcase_32 AC 13 ms
4,348 KB
testcase_33 AC 116 ms
4,348 KB
testcase_34 AC 192 ms
4,348 KB
testcase_35 AC 445 ms
4,348 KB
testcase_36 AC 60 ms
4,348 KB
testcase_37 AC 320 ms
4,348 KB
testcase_38 AC 260 ms
4,348 KB
testcase_39 AC 427 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 368 ms
4,348 KB
testcase_43 AC 401 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


Int isprime(Int x){
  if(x<=1) return 0;
  for(Int i=2;i*i<=x;i++)
    if(x%i==0) return 0;
  return 1;
}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> ps;
  for(Int i=2;i<=n;i++)
    if(isprime(i)) ps.emplace_back(i);

  const Int MAX = 1e6+10;
  vector<Int> qs;
  Int ans=0;
  for(Int r:ps){
    if(r>MAX/r+1) break;
    for(Int p:ps){
      if(binary_search(ps.begin(),ps.end(),r*r-p)) ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}
0