結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,500 KB
testcase_01 AC 20 ms
4,892 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 15 ms
4,508 KB
testcase_08 AC 17 ms
4,704 KB
testcase_09 AC 20 ms
4,880 KB
testcase_10 AC 16 ms
4,632 KB
testcase_11 AC 18 ms
4,796 KB
testcase_12 AC 19 ms
4,888 KB
testcase_13 AC 19 ms
4,828 KB
testcase_14 AC 19 ms
4,836 KB
testcase_15 AC 15 ms
4,588 KB
testcase_16 AC 15 ms
4,600 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 WA -
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 4 ms
4,380 KB
testcase_21 AC 3 ms
4,376 KB
testcase_22 AC 9 ms
4,376 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 4 ms
4,380 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 20 ms
4,852 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 18 ms
4,856 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 20 ms
4,824 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 5 ms
4,380 KB
testcase_34 AC 8 ms
4,376 KB
testcase_35 AC 20 ms
4,924 KB
testcase_36 AC 4 ms
4,376 KB
testcase_37 AC 14 ms
4,408 KB
testcase_38 AC 11 ms
4,380 KB
testcase_39 AC 20 ms
4,864 KB
testcase_40 WA -
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 16 ms
4,660 KB
testcase_43 AC 18 ms
4,776 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;
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=float(sqrt((double)n))+0.1;
    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