結果

問題 No.732 3PrimeCounting
ユーザー dama_mathdama_math
提出日時 2018-09-07 23:08:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 997 bytes
コンパイル時間 1,676 ms
コンパイル使用メモリ 168,328 KB
実行使用メモリ 4,904 KB
最終ジャッジ日時 2023-08-19 22:29:32
合計ジャッジ時間 15,973 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,596 KB
testcase_01 AC 3 ms
4,512 KB
testcase_02 AC 3 ms
4,468 KB
testcase_03 AC 3 ms
4,516 KB
testcase_04 AC 2 ms
4,716 KB
testcase_05 AC 2 ms
4,516 KB
testcase_06 AC 3 ms
4,528 KB
testcase_07 AC 2 ms
4,460 KB
testcase_08 AC 3 ms
4,472 KB
testcase_09 AC 3 ms
4,576 KB
testcase_10 AC 2 ms
4,576 KB
testcase_11 AC 3 ms
4,524 KB
testcase_12 AC 3 ms
4,584 KB
testcase_13 AC 3 ms
4,776 KB
testcase_14 AC 2 ms
4,468 KB
testcase_15 AC 3 ms
4,744 KB
testcase_16 AC 3 ms
4,580 KB
testcase_17 AC 2 ms
4,548 KB
testcase_18 AC 2 ms
4,532 KB
testcase_19 AC 3 ms
4,464 KB
testcase_20 AC 2 ms
4,492 KB
testcase_21 AC 3 ms
4,476 KB
testcase_22 AC 4 ms
4,532 KB
testcase_23 AC 3 ms
4,784 KB
testcase_24 AC 3 ms
4,724 KB
testcase_25 AC 7 ms
4,596 KB
testcase_26 AC 5 ms
4,476 KB
testcase_27 AC 3 ms
4,552 KB
testcase_28 AC 3 ms
4,580 KB
testcase_29 AC 3 ms
4,656 KB
testcase_30 AC 3 ms
4,464 KB
testcase_31 AC 4 ms
4,592 KB
testcase_32 AC 6 ms
4,556 KB
testcase_33 AC 6 ms
4,592 KB
testcase_34 AC 6 ms
4,592 KB
testcase_35 AC 5 ms
4,588 KB
testcase_36 AC 5 ms
4,600 KB
testcase_37 AC 2 ms
4,528 KB
testcase_38 AC 3 ms
4,468 KB
testcase_39 AC 5 ms
4,600 KB
testcase_40 AC 4 ms
4,532 KB
testcase_41 AC 4 ms
4,664 KB
testcase_42 AC 4 ms
4,524 KB
testcase_43 AC 4 ms
4,580 KB
testcase_44 AC 4 ms
4,492 KB
testcase_45 AC 3 ms
4,580 KB
testcase_46 AC 3 ms
4,596 KB
testcase_47 AC 3 ms
4,552 KB
testcase_48 AC 7 ms
4,480 KB
testcase_49 AC 7 ms
4,524 KB
testcase_50 AC 4 ms
4,588 KB
testcase_51 AC 4 ms
4,472 KB
testcase_52 AC 3 ms
4,580 KB
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 AC 57 ms
4,520 KB
testcase_58 AC 57 ms
4,700 KB
testcase_59 RE -
testcase_60 AC 75 ms
4,604 KB
testcase_61 AC 74 ms
4,600 KB
testcase_62 WA -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 AC 2 ms
4,648 KB
testcase_67 AC 3 ms
4,648 KB
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
testcase_73 WA -
testcase_74 WA -
testcase_75 AC 7 ms
4,532 KB
testcase_76 RE -
testcase_77 AC 60 ms
4,524 KB
testcase_78 WA -
testcase_79 RE -
testcase_80 WA -
testcase_81 RE -
testcase_82 AC 2 ms
4,520 KB
testcase_83 AC 59 ms
4,544 KB
testcase_84 AC 63 ms
4,712 KB
testcase_85 RE -
testcase_86 AC 608 ms
4,768 KB
testcase_87 WA -
testcase_88 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
using namespace std;

//素数判定
bool pj(int n){
    if(n==1) return false;
    int d=2;
    while(d*d<=n){
        if(n%d==0)return false;
        d++;
    }
    return true;
}

int m[300000];
vector<int> v;
int main(){
    int n; cin>>n;
    memset(m,0,sizeof(m));
    FOR(i,1,3*n+1) if(pj(i)) v.PB(i);
    for(int i=0;v[i]<=n;i++){
        for(int j=0;v[j]<=n;j++){
            m[v[i]+v[j]]++;
        }
    }
    ll ans1=0,ans2=0;
    for(int i=0;v[i]<=3*n;i++){
        for(int j=0;v[j]<=n;j++){
            if(v[i]>v[j]){
                ans1+=m[v[i]-v[j]];
            }
        }
    }
    memset(m,0,sizeof(m));
    for(int i=0;v[i]<=n;i++){
        m[2*v[i]]++;
    }
    for(int i=0;v[i]<=3*n;i++){
        for(int j=0;v[j]<=n;j++){
            if(v[i]>v[j]){
                ans2+=m[v[i]-v[j]];
            }
        }
    }
    cout<<(ans1-ans2*3)/6<<endl;
    return 0;
}
0