結果

問題 No.732 3PrimeCounting
ユーザー donkorin_donkorin_
提出日時 2018-09-09 16:14:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,562 bytes
コンパイル時間 1,635 ms
コンパイル使用メモリ 165,448 KB
実行使用メモリ 6,428 KB
最終ジャッジ日時 2023-08-25 02:18:17
合計ジャッジ時間 10,621 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,420 KB
testcase_01 AC 2 ms
5,424 KB
testcase_02 AC 3 ms
5,424 KB
testcase_03 AC 1 ms
5,416 KB
testcase_04 AC 2 ms
5,472 KB
testcase_05 AC 1 ms
5,424 KB
testcase_06 WA -
testcase_07 AC 2 ms
5,424 KB
testcase_08 WA -
testcase_09 AC 2 ms
5,424 KB
testcase_10 AC 1 ms
5,488 KB
testcase_11 AC 1 ms
5,488 KB
testcase_12 WA -
testcase_13 AC 1 ms
5,496 KB
testcase_14 AC 3 ms
5,416 KB
testcase_15 AC 1 ms
5,424 KB
testcase_16 AC 2 ms
5,428 KB
testcase_17 AC 1 ms
5,424 KB
testcase_18 WA -
testcase_19 AC 1 ms
5,420 KB
testcase_20 AC 2 ms
5,616 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 AC 2 ms
5,424 KB
testcase_24 AC 1 ms
5,420 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 2 ms
5,428 KB
testcase_28 AC 3 ms
5,480 KB
testcase_29 RE -
testcase_30 AC 2 ms
5,632 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 2 ms
5,584 KB
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 AC 3 ms
5,552 KB
testcase_38 AC 4 ms
5,428 KB
testcase_39 RE -
testcase_40 AC 2 ms
5,648 KB
testcase_41 RE -
testcase_42 AC 2 ms
5,568 KB
testcase_43 AC 2 ms
5,716 KB
testcase_44 RE -
testcase_45 AC 3 ms
5,616 KB
testcase_46 AC 3 ms
5,436 KB
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 RE -
testcase_52 AC 2 ms
5,432 KB
testcase_53 AC 4 ms
5,504 KB
testcase_54 AC 40 ms
5,900 KB
testcase_55 RE -
testcase_56 RE -
testcase_57 AC 9 ms
5,732 KB
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 AC 12 ms
5,660 KB
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 AC 2 ms
5,488 KB
testcase_67 WA -
testcase_68 AC 45 ms
6,016 KB
testcase_69 RE -
testcase_70 AC 39 ms
5,912 KB
testcase_71 RE -
testcase_72 RE -
testcase_73 RE -
testcase_74 RE -
testcase_75 RE -
testcase_76 RE -
testcase_77 AC 9 ms
5,612 KB
testcase_78 AC 67 ms
6,112 KB
testcase_79 AC 46 ms
5,944 KB
testcase_80 AC 60 ms
6,156 KB
testcase_81 AC 41 ms
5,920 KB
testcase_82 AC 2 ms
5,492 KB
testcase_83 AC 9 ms
5,884 KB
testcase_84 AC 10 ms
5,700 KB
testcase_85 RE -
testcase_86 AC 59 ms
6,160 KB
testcase_87 RE -
testcase_88 AC 115 ms
6,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

static const int MAX_PRIME = 1000000;
bool is_prime[MAX_PRIME];
int primes[MAX_PRIME], prime_cnt;
void make_prime(int N)
{
    erep(i, 0, N) is_prime[i] = true;
    is_prime[0] = false;
    is_prime[1] = false;
    erep(i, 2, N)
    {
        if (is_prime[i])
            primes[prime_cnt++] = i;
        for (int j = 2 * i; j <= N; j += i)
            is_prime[j] = false;
    }
}

int n, cnt[400001];
ll ans;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    make_prime(3*n + 1);
    int a, b, c;
    for (c = 2; primes[c] <= n; c++) {
        b = c - 1;
        rep(a, 0, b) cnt[primes[a] + primes[b]]++;
        for(int t = c + 1; primes[t] <= primes[c] * 3; t++) 
            ans += cnt[primes[t] - primes[c]];  
    } 
    cout << ans << endl;
    return 0;
}
0