結果

問題 No.732 3PrimeCounting
ユーザー dama_mathdama_math
提出日時 2018-09-07 23:15:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 728 ms / 3,000 ms
コード長 1,012 bytes
コンパイル時間 2,180 ms
コンパイル使用メモリ 167,352 KB
実行使用メモリ 4,916 KB
最終ジャッジ日時 2023-08-19 22:44:50
合計ジャッジ時間 12,345 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,524 KB
testcase_01 AC 3 ms
4,500 KB
testcase_02 AC 2 ms
4,468 KB
testcase_03 AC 2 ms
4,688 KB
testcase_04 AC 3 ms
4,728 KB
testcase_05 AC 2 ms
4,480 KB
testcase_06 AC 2 ms
4,476 KB
testcase_07 AC 2 ms
4,612 KB
testcase_08 AC 2 ms
4,516 KB
testcase_09 AC 3 ms
4,468 KB
testcase_10 AC 2 ms
4,460 KB
testcase_11 AC 3 ms
4,612 KB
testcase_12 AC 3 ms
4,636 KB
testcase_13 AC 2 ms
4,664 KB
testcase_14 AC 2 ms
4,484 KB
testcase_15 AC 2 ms
4,476 KB
testcase_16 AC 2 ms
4,688 KB
testcase_17 AC 2 ms
4,476 KB
testcase_18 AC 2 ms
4,480 KB
testcase_19 AC 2 ms
4,532 KB
testcase_20 AC 2 ms
4,492 KB
testcase_21 AC 3 ms
4,504 KB
testcase_22 AC 4 ms
4,584 KB
testcase_23 AC 2 ms
4,656 KB
testcase_24 AC 2 ms
4,496 KB
testcase_25 AC 5 ms
4,580 KB
testcase_26 AC 4 ms
4,748 KB
testcase_27 AC 3 ms
4,480 KB
testcase_28 AC 2 ms
4,500 KB
testcase_29 AC 3 ms
4,504 KB
testcase_30 AC 3 ms
4,484 KB
testcase_31 AC 4 ms
4,500 KB
testcase_32 AC 5 ms
4,500 KB
testcase_33 AC 5 ms
4,696 KB
testcase_34 AC 4 ms
4,492 KB
testcase_35 AC 3 ms
4,640 KB
testcase_36 AC 4 ms
4,576 KB
testcase_37 AC 2 ms
4,484 KB
testcase_38 AC 3 ms
4,532 KB
testcase_39 AC 4 ms
4,488 KB
testcase_40 AC 4 ms
4,464 KB
testcase_41 AC 3 ms
4,472 KB
testcase_42 AC 3 ms
4,488 KB
testcase_43 AC 3 ms
4,652 KB
testcase_44 AC 3 ms
4,460 KB
testcase_45 AC 2 ms
4,636 KB
testcase_46 AC 2 ms
4,472 KB
testcase_47 AC 2 ms
4,484 KB
testcase_48 AC 6 ms
4,664 KB
testcase_49 AC 6 ms
4,468 KB
testcase_50 AC 3 ms
4,496 KB
testcase_51 AC 4 ms
4,636 KB
testcase_52 AC 3 ms
4,528 KB
testcase_53 AC 15 ms
4,812 KB
testcase_54 AC 248 ms
4,620 KB
testcase_55 AC 248 ms
4,656 KB
testcase_56 AC 249 ms
4,620 KB
testcase_57 AC 46 ms
4,532 KB
testcase_58 AC 46 ms
4,552 KB
testcase_59 AC 17 ms
4,500 KB
testcase_60 AC 71 ms
4,748 KB
testcase_61 AC 70 ms
4,696 KB
testcase_62 AC 328 ms
4,596 KB
testcase_63 AC 136 ms
4,564 KB
testcase_64 AC 92 ms
4,712 KB
testcase_65 AC 91 ms
4,616 KB
testcase_66 AC 3 ms
4,536 KB
testcase_67 AC 3 ms
4,496 KB
testcase_68 AC 283 ms
4,600 KB
testcase_69 AC 282 ms
4,916 KB
testcase_70 AC 252 ms
4,680 KB
testcase_71 AC 252 ms
4,612 KB
testcase_72 AC 127 ms
4,744 KB
testcase_73 AC 540 ms
4,780 KB
testcase_74 AC 540 ms
4,580 KB
testcase_75 AC 5 ms
4,588 KB
testcase_76 AC 275 ms
4,664 KB
testcase_77 AC 50 ms
4,528 KB
testcase_78 AC 412 ms
4,668 KB
testcase_79 AC 287 ms
4,912 KB
testcase_80 AC 366 ms
4,692 KB
testcase_81 AC 256 ms
4,636 KB
testcase_82 AC 2 ms
4,572 KB
testcase_83 AC 48 ms
4,556 KB
testcase_84 AC 55 ms
4,580 KB
testcase_85 AC 212 ms
4,596 KB
testcase_86 AC 377 ms
4,644 KB
testcase_87 AC 725 ms
4,604 KB
testcase_88 AC 728 ms
4,620 KB
権限があれば一括ダウンロードができます

ソースコード

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);
    v.PB(1e9);
    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