結果
問題 | No.732 3PrimeCounting |
ユーザー |
![]() |
提出日時 | 2023-07-18 22:31:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 580 ms / 3,000 ms |
コード長 | 2,040 bytes |
コンパイル時間 | 3,484 ms |
コンパイル使用メモリ | 251,788 KB |
最終ジャッジ日時 | 2025-02-15 15:40:12 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 89 |
ソースコード
#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);