結果

問題 No.843 Triple Primes
ユーザー NacoNaco
提出日時 2019-07-01 15:20:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,303 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 1,370 ms
コンパイル使用メモリ 69,904 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 17:59:26
合計ジャッジ時間 26,605 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1,303 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 3 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 872 ms
4,348 KB
testcase_08 AC 1,026 ms
4,348 KB
testcase_09 AC 1,292 ms
4,348 KB
testcase_10 AC 939 ms
4,348 KB
testcase_11 AC 1,111 ms
4,348 KB
testcase_12 AC 1,239 ms
4,348 KB
testcase_13 AC 1,175 ms
4,348 KB
testcase_14 AC 1,184 ms
4,348 KB
testcase_15 AC 899 ms
4,348 KB
testcase_16 AC 918 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 122 ms
4,348 KB
testcase_21 AC 42 ms
4,348 KB
testcase_22 AC 443 ms
4,348 KB
testcase_23 AC 481 ms
4,348 KB
testcase_24 AC 133 ms
4,348 KB
testcase_25 AC 82 ms
4,348 KB
testcase_26 AC 1,284 ms
4,348 KB
testcase_27 AC 9 ms
4,348 KB
testcase_28 AC 1,198 ms
4,348 KB
testcase_29 AC 151 ms
4,348 KB
testcase_30 AC 1,257 ms
4,348 KB
testcase_31 AC 18 ms
4,348 KB
testcase_32 AC 8 ms
4,348 KB
testcase_33 AC 180 ms
4,348 KB
testcase_34 AC 380 ms
4,348 KB
testcase_35 AC 1,296 ms
4,348 KB
testcase_36 AC 67 ms
4,348 KB
testcase_37 AC 810 ms
4,348 KB
testcase_38 AC 591 ms
4,348 KB
testcase_39 AC 1,218 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 974 ms
4,348 KB
testcase_43 AC 1,111 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

vector<bool> prime_table(int n){ //素数全列挙
    vector<bool> prime(n+1,true);
    prime[0]=prime[1]=false;
    for(int i=2;i*i<=n;i++){
        if(prime[i]!=true) continue;
        for(int j=2*i;j<=n;j+=i){
            prime[j]=false;
        }
    }
    return prime; //i番目の要素が素数の場合trueを返す
}

int main(){
    int N;
    cin >> N;
    vector<bool> eratos;
    eratos=prime_table(N);
    vector<long long> res;
    for(int i=0;i<=N;i++){
        if(eratos[i]==true){
            res.push_back(i);
        }
    }
    int ans=0;
    for(int i=0;i<res.size();i++){
        for(int j=0;j<res.size();j++){
            long long k=res[i]*res[i]-res[j];
            if(k>=0&&k<=N){
                if(eratos[k]==true){
                    ans++;
                    //cout << res[i] << res[j] << endl;
                }
            }
        }
    }
    cout << ans << endl;
}
0