結果

問題 No.732 3PrimeCounting
ユーザー batasanblogbatasanblog
提出日時 2023-07-18 22:31:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 628 ms / 3,000 ms
コード長 2,040 bytes
コンパイル時間 5,251 ms
コンパイル使用メモリ 263,900 KB
実行使用メモリ 6,184 KB
最終ジャッジ日時 2023-10-19 01:55:58
合計ジャッジ時間 12,687 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 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 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 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 2 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 4 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 3 ms
4,348 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 3 ms
4,348 KB
testcase_35 AC 3 ms
4,348 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 2 ms
4,348 KB
testcase_39 AC 3 ms
4,348 KB
testcase_40 AC 3 ms
4,348 KB
testcase_41 AC 3 ms
4,348 KB
testcase_42 AC 3 ms
4,348 KB
testcase_43 AC 3 ms
4,348 KB
testcase_44 AC 3 ms
4,348 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
testcase_47 AC 2 ms
4,348 KB
testcase_48 AC 3 ms
4,348 KB
testcase_49 AC 4 ms
4,348 KB
testcase_50 AC 2 ms
4,348 KB
testcase_51 AC 2 ms
4,348 KB
testcase_52 AC 2 ms
4,348 KB
testcase_53 AC 7 ms
4,348 KB
testcase_54 AC 137 ms
5,044 KB
testcase_55 AC 154 ms
5,044 KB
testcase_56 AC 150 ms
5,044 KB
testcase_57 AC 20 ms
4,348 KB
testcase_58 AC 20 ms
4,348 KB
testcase_59 AC 9 ms
4,348 KB
testcase_60 AC 30 ms
4,348 KB
testcase_61 AC 30 ms
4,348 KB
testcase_62 AC 211 ms
5,112 KB
testcase_63 AC 62 ms
4,512 KB
testcase_64 AC 40 ms
4,348 KB
testcase_65 AC 41 ms
4,348 KB
testcase_66 AC 2 ms
4,348 KB
testcase_67 AC 2 ms
4,348 KB
testcase_68 AC 170 ms
5,048 KB
testcase_69 AC 164 ms
5,048 KB
testcase_70 AC 144 ms
5,048 KB
testcase_71 AC 145 ms
5,048 KB
testcase_72 AC 56 ms
4,512 KB
testcase_73 AC 433 ms
5,648 KB
testcase_74 AC 447 ms
5,648 KB
testcase_75 AC 3 ms
4,348 KB
testcase_76 AC 165 ms
5,048 KB
testcase_77 AC 22 ms
4,348 KB
testcase_78 AC 283 ms
5,380 KB
testcase_79 AC 166 ms
5,048 KB
testcase_80 AC 237 ms
5,380 KB
testcase_81 AC 149 ms
5,048 KB
testcase_82 AC 2 ms
4,348 KB
testcase_83 AC 21 ms
4,348 KB
testcase_84 AC 24 ms
4,348 KB
testcase_85 AC 115 ms
4,780 KB
testcase_86 AC 258 ms
5,380 KB
testcase_87 AC 628 ms
6,184 KB
testcase_88 AC 604 ms
6,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
//using mint = static_modint<998244353>;
using mint = static_modint<1000000007>;
ostream &operator<<(ostream &o,const mint &m){cout<<m.val();return o;}
using ll = long long;
using pl = pair<ll,ll>;
using vl = vector<ll>;
template<class T> using ve = vector<T>;
template<class T> using vv = vector<ve<T>>;
template<class T> using vvv = vector<vv<T>>;
#define rep(i,n) for(ll i=0;i<(ll)(n);++i)
#define reps(i,s,n) for(ll i=(s);i<(ll)(n);++i)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define be(v) (v).begin(),(v).end()
const long long INF = 1e18;
#ifdef DEBUG
#include <debug.hpp>
random_device rd;
mt19937 gen(rd());
ll random(ll l,ll h){
	uniform_int_distribution<ll> dist(l,h);
	return dist(gen);
}
#endif

vector<long long> prime_number(const long long N) {
	vector<bool> is_prime(N+1,true);
 	vector<ll> P;
	for(ll i = 2; i <= N; i++ ) {
    if( is_prime[ i ] ) {
      for( ll j = 2 * i; j <= N; j += i ) {
        is_prime[ j ] = false;
    	}
    	P.emplace_back( i );
  	}
	}
	return P;
}
ll N;
void input(){
	cin>>N;
}
#ifdef DEBUG
void showall(){
	show(N);
}
#endif
ll logic(){
	ll ans=0;
	vl p = prime_number(3*N);
	vl cnt(3*N+1,0);
	for(ll i = 2; p.at(i) <= N; ++i){
		rep(j,i-1){
			cnt.at(p.at(j)+p.at(i-1))++;
		}
		reps(j,i+1,p.size()){
			ans += cnt.at(p.at(j) - p.at(i));
		}
	}
	return ans;
}
#ifdef DEBUG
ll naive(){
	return 1;
}
#endif
int main(){
	input();
	#ifdef DEBUG
	showall();
	cout << "--- Logic ---" << endl;
	#endif
	ll ans=logic();
	cout<<ans<<endl;
	//if(logic())cout<<"Yes"<<endl;
	//else cout<<"No"<<endl;
	//while(input())logic();
	#ifdef DEBUG
	//show("naive=",naive());
	#endif
	#ifdef DEBUG
	/*
	rep(q,100){
		N=random(1LL,1000LL);
		showall();
		ll lans=logic(),nans=naive();
		if(lans!=nans){ show(" WA",lans,nans); break; }
		else{ show(" AC",lans,nans); }
	}
	*/
	#endif
	return 0;
}
//cout << fixed << setprecision(9);
0