結果

問題 No.843 Triple Primes
ユーザー tarattata1tarattata1
提出日時 2019-06-29 12:17:34
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,315 bytes
コンパイル時間 594 ms
コンパイル使用メモリ 77,160 KB
実行使用メモリ 4,960 KB
最終ジャッジ日時 2023-09-14 23:10:22
合計ジャッジ時間 2,749 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 21 ms
4,900 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 15 ms
4,484 KB
testcase_08 AC 17 ms
4,696 KB
testcase_09 AC 20 ms
4,904 KB
testcase_10 AC 16 ms
4,608 KB
testcase_11 WA -
testcase_12 AC 20 ms
4,960 KB
testcase_13 AC 18 ms
4,824 KB
testcase_14 AC 19 ms
4,792 KB
testcase_15 AC 16 ms
4,516 KB
testcase_16 AC 17 ms
4,576 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 8 ms
4,380 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 4 ms
4,376 KB
testcase_26 AC 20 ms
4,936 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 19 ms
4,848 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 20 ms
4,896 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 5 ms
4,376 KB
testcase_34 AC 8 ms
4,380 KB
testcase_35 AC 20 ms
4,928 KB
testcase_36 AC 3 ms
4,380 KB
testcase_37 AC 14 ms
4,424 KB
testcase_38 WA -
testcase_39 AC 19 ms
4,868 KB
testcase_40 WA -
testcase_41 AC 2 ms
4,376 KB
testcase_42 WA -
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
vector<int> a;

void preparePrime( int maxp )
{
    int i;
    a.resize(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;

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


    return 0;
}
0