結果

問題 No.843 Triple Primes
ユーザー ShibuyapShibuyap
提出日時 2019-10-13 11:09:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 1,542 bytes
コンパイル時間 1,567 ms
コンパイル使用メモリ 169,480 KB
実行使用メモリ 8,880 KB
最終ジャッジ日時 2023-08-21 04:54:29
合計ジャッジ時間 12,205 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 196 ms
8,472 KB
testcase_01 AC 196 ms
8,628 KB
testcase_02 AC 196 ms
8,504 KB
testcase_03 AC 196 ms
8,452 KB
testcase_04 AC 195 ms
8,580 KB
testcase_05 AC 196 ms
8,616 KB
testcase_06 AC 196 ms
8,340 KB
testcase_07 AC 196 ms
8,476 KB
testcase_08 AC 196 ms
8,412 KB
testcase_09 AC 196 ms
8,384 KB
testcase_10 AC 196 ms
8,456 KB
testcase_11 AC 196 ms
8,484 KB
testcase_12 AC 196 ms
8,784 KB
testcase_13 AC 196 ms
8,496 KB
testcase_14 AC 196 ms
8,584 KB
testcase_15 AC 196 ms
8,324 KB
testcase_16 AC 196 ms
8,680 KB
testcase_17 AC 196 ms
8,428 KB
testcase_18 AC 197 ms
8,880 KB
testcase_19 AC 197 ms
8,512 KB
testcase_20 AC 197 ms
8,576 KB
testcase_21 AC 197 ms
8,512 KB
testcase_22 AC 200 ms
8,376 KB
testcase_23 AC 197 ms
8,404 KB
testcase_24 AC 196 ms
8,196 KB
testcase_25 AC 196 ms
8,356 KB
testcase_26 AC 196 ms
8,536 KB
testcase_27 AC 196 ms
8,412 KB
testcase_28 AC 196 ms
8,504 KB
testcase_29 AC 197 ms
8,368 KB
testcase_30 AC 196 ms
8,384 KB
testcase_31 AC 196 ms
8,456 KB
testcase_32 AC 196 ms
8,416 KB
testcase_33 AC 196 ms
8,340 KB
testcase_34 AC 195 ms
8,504 KB
testcase_35 AC 197 ms
8,388 KB
testcase_36 AC 196 ms
8,596 KB
testcase_37 AC 197 ms
8,412 KB
testcase_38 AC 196 ms
8,384 KB
testcase_39 AC 196 ms
8,544 KB
testcase_40 AC 196 ms
8,360 KB
testcase_41 AC 196 ms
8,416 KB
testcase_42 AC 196 ms
8,520 KB
testcase_43 AC 196 ms
8,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


/*
    Max_Prime以下の素数をprimes[]に格納
*/

const int Max_Prime = 1000000;
vector<int> tmp_primes;
vector<ll> primes;

void PrimeInit() {
    rep(i,Max_Prime-1){
        tmp_primes.push_back(i+2);
    }

    int rem = Max_Prime - 1;
    int count = 0;
    while(rem>0){
        if(tmp_primes[0]*tmp_primes[0] > Max_Prime){
            rep(i,rem){
                primes.push_back(tmp_primes[i]);
                count++;
            }
            break;
        }
        primes.push_back(tmp_primes[0]);
        count++;
        int count2 = 0;
        srep(i,1,rem){
            if(tmp_primes[i] % primes[count-1] != 0){
                tmp_primes[count2] = tmp_primes[i];
                count2++;
            }
        }
        rem = count2;
    }
}

int main(){
    PrimeInit();
    ll n; cin >> n;
    int ans = 0;
    rep(i,primes.size()){
        if(primes[i] * primes[i] - 2 > n)break;
        if(binary_search(primes.begin(), primes.end(), primes[i] * primes[i] - 2))ans++;
    }

    if(ans>0)ans = ans*2-1;
    cout << ans << endl;
    return 0;
}
 
 
0