結果

問題 No.843 Triple Primes
ユーザー tarattata1tarattata1
提出日時 2019-06-29 12:08:36
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,349 bytes
コンパイル時間 906 ms
コンパイル使用メモリ 76,896 KB
実行使用メモリ 5,004 KB
最終ジャッジ日時 2023-09-14 23:08:58
合計ジャッジ時間 3,203 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 23 ms
5,004 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 17 ms
4,604 KB
testcase_08 AC 19 ms
4,728 KB
testcase_09 AC 22 ms
4,936 KB
testcase_10 AC 17 ms
4,724 KB
testcase_11 AC 20 ms
4,756 KB
testcase_12 AC 21 ms
4,928 KB
testcase_13 AC 21 ms
4,820 KB
testcase_14 AC 21 ms
4,840 KB
testcase_15 AC 17 ms
4,600 KB
testcase_16 AC 18 ms
4,660 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 WA -
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 5 ms
4,384 KB
testcase_21 AC 3 ms
4,384 KB
testcase_22 AC 10 ms
4,380 KB
testcase_23 AC 10 ms
4,380 KB
testcase_24 AC 5 ms
4,380 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 22 ms
4,984 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 21 ms
4,940 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 21 ms
4,920 KB
testcase_31 AC 3 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 6 ms
4,384 KB
testcase_34 AC 9 ms
4,384 KB
testcase_35 AC 22 ms
4,960 KB
testcase_36 AC 4 ms
4,384 KB
testcase_37 AC 16 ms
4,496 KB
testcase_38 AC 12 ms
4,380 KB
testcase_39 AC 21 ms
4,876 KB
testcase_40 WA -
testcase_41 AC 1 ms
4,384 KB
testcase_42 WA -
testcase_43 AC 20 ms
4,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

vector<int> pp;
void preparePrime( int maxp )
{
    int i;
    vector<int> a(maxp+1);
    for(i=2; i<=maxp; i++) {
        int k=i+i;
        while(k<=maxp) {
            a[k]=1;
            k+=i;
        }
    }
    for(i=2; i<=maxp; i++) {
        if(a[i]==0) pp.push_back( i );
    }
    return;
}


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    preparePrime( n );

    int cnt=0;
    int i, j;

    vector<int> save(n+1);
    for(j=0; j<(int)pp.size(); j++) {
        save[pp[j]]=1;
    }
    double lim=sqrt((double)n)+0.001;
    for(i=2; i<=lim; i++) {
        if(save[i]==0) continue;
        int k = i*i;
        for(j=0; j<(int)pp.size(); j++) {
            int val=k-pp[j];
            if(val<2) break;
            if (save[val]) {
                cnt++;
            }
        }        
    }
    printf("%d\n", cnt);


    return 0;
}
0