結果

問題 No.732 3PrimeCounting
ユーザー dama_math
提出日時 2018-09-07 22:52:02
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 1,346 bytes
コンパイル時間 1,466 ms
コンパイル使用メモリ 161,280 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-29 17:50:09
合計ジャッジ時間 14,869 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 72 RE * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;

//素数判定
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 main(){
    int n; cin>>n;
    vector<int> v;
    int m[300000]={};
    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]];
            }
        }
    }
    co((ans1-ans2*3)/6);
    return 0;
}
0