結果

問題 No.843 Triple Primes
ユーザー tomarint2tomarint2
提出日時 2019-06-28 22:00:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 1,303 bytes
コンパイル時間 789 ms
コンパイル使用メモリ 81,876 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2023-10-19 17:42:55
合計ジャッジ時間 2,215 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 9 ms
12,032 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 8 ms
10,420 KB
testcase_08 AC 8 ms
10,916 KB
testcase_09 AC 9 ms
12,032 KB
testcase_10 AC 8 ms
10,700 KB
testcase_11 AC 8 ms
11,464 KB
testcase_12 AC 8 ms
11,756 KB
testcase_13 AC 9 ms
11,480 KB
testcase_14 AC 8 ms
11,480 KB
testcase_15 AC 8 ms
10,428 KB
testcase_16 AC 8 ms
10,696 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 5 ms
5,880 KB
testcase_21 AC 3 ms
4,632 KB
testcase_22 AC 6 ms
8,128 KB
testcase_23 AC 7 ms
8,404 KB
testcase_24 AC 5 ms
5,888 KB
testcase_25 AC 4 ms
5,328 KB
testcase_26 AC 9 ms
12,028 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 8 ms
11,748 KB
testcase_29 AC 5 ms
6,160 KB
testcase_30 AC 9 ms
11,760 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 5 ms
6,440 KB
testcase_34 AC 6 ms
7,840 KB
testcase_35 AC 8 ms
12,032 KB
testcase_36 AC 4 ms
5,052 KB
testcase_37 AC 7 ms
10,012 KB
testcase_38 AC 8 ms
8,964 KB
testcase_39 AC 9 ms
11,752 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 8 ms
10,904 KB
testcase_43 AC 8 ms
11,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0

void solve()
{
    ll N;
    cin >> N;
    char isPrime[N+1];
    for1(i,N+1) {
        isPrime[i] = 1;
    }
    isPrime[1] = 0;
    for2 (i,2,N+1) {
        if (!isPrime[i]) continue;
        for3(j,i*2,N+1,i) {
            isPrime[j] = 0;
        }
    }
    vector<ll> primes;
    for2 (i,2,N+1) {
        if (isPrime[i]) {
            primes.push_back(i);
        }
    }
    vector<ll> r2(N*2+1,0);
    for (auto p : primes) {
        ll r = p * p;
        if (r <= N*2) {
            r2[r] = 1;
        }
    }

    ll ans = 0;
    for (auto p : primes) {
        ll r = p + 2;
        //cout << p << " " << q << " " << r << endl;
        if (r2[r]) {
            ++ans;
        }
    }
    if (ans == 0) {
        cout << 0 << endl;
    } else {
        cout << ans*2-1 << endl;
    }
}

int main()
{
    do {
        solve();
    } while (DEBUG);
}
0