結果

問題 No.843 Triple Primes
ユーザー tarattata1tarattata1
提出日時 2019-06-29 12:20:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,299 bytes
コンパイル時間 1,367 ms
コンパイル使用メモリ 74,668 KB
実行使用メモリ 4,984 KB
最終ジャッジ日時 2023-10-19 17:52:18
合計ジャッジ時間 2,575 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 23 ms
4,984 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 18 ms
4,596 KB
testcase_08 AC 20 ms
4,744 KB
testcase_09 AC 24 ms
4,972 KB
testcase_10 AC 18 ms
4,656 KB
testcase_11 AC 21 ms
4,824 KB
testcase_12 AC 22 ms
4,928 KB
testcase_13 AC 22 ms
4,876 KB
testcase_14 AC 22 ms
4,876 KB
testcase_15 AC 18 ms
4,624 KB
testcase_16 AC 19 ms
4,644 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 5 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 11 ms
4,348 KB
testcase_23 AC 11 ms
4,348 KB
testcase_24 AC 6 ms
4,348 KB
testcase_25 AC 5 ms
4,348 KB
testcase_26 AC 24 ms
4,968 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 23 ms
4,896 KB
testcase_29 AC 6 ms
4,348 KB
testcase_30 AC 23 ms
4,940 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 6 ms
4,348 KB
testcase_34 AC 10 ms
4,348 KB
testcase_35 AC 23 ms
4,972 KB
testcase_36 AC 4 ms
4,348 KB
testcase_37 AC 16 ms
4,472 KB
testcase_38 AC 13 ms
4,348 KB
testcase_39 AC 22 ms
4,912 KB
testcase_40 AC 1 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 19 ms
4,696 KB
testcase_43 AC 21 ms
4,820 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:48:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   48 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~

ソースコード

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*2))+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