結果

問題 No.2620 Sieve of Coins
ユーザー 👑 potato167potato167
提出日時 2024-01-27 02:16:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 3,786 bytes
コンパイル時間 2,741 ms
コンパイル使用メモリ 220,136 KB
実行使用メモリ 9,148 KB
最終ジャッジ日時 2024-01-27 02:16:41
合計ジャッジ時間 7,604 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
9,144 KB
testcase_01 AC 17 ms
9,144 KB
testcase_02 AC 16 ms
9,144 KB
testcase_03 AC 67 ms
9,144 KB
testcase_04 AC 133 ms
9,144 KB
testcase_05 AC 16 ms
9,144 KB
testcase_06 AC 17 ms
9,144 KB
testcase_07 AC 16 ms
9,144 KB
testcase_08 AC 17 ms
9,144 KB
testcase_09 AC 16 ms
9,144 KB
testcase_10 AC 17 ms
9,144 KB
testcase_11 AC 16 ms
9,148 KB
testcase_12 AC 16 ms
9,144 KB
testcase_13 AC 16 ms
9,144 KB
testcase_14 AC 16 ms
9,148 KB
testcase_15 AC 16 ms
9,144 KB
testcase_16 AC 17 ms
9,144 KB
testcase_17 AC 18 ms
9,144 KB
testcase_18 AC 65 ms
9,144 KB
testcase_19 AC 65 ms
9,144 KB
testcase_20 AC 16 ms
9,144 KB
testcase_21 AC 51 ms
9,144 KB
testcase_22 AC 51 ms
9,144 KB
testcase_23 AC 19 ms
9,144 KB
testcase_24 AC 17 ms
9,144 KB
testcase_25 AC 16 ms
9,144 KB
testcase_26 AC 17 ms
9,144 KB
testcase_27 AC 16 ms
9,144 KB
testcase_28 AC 16 ms
9,144 KB
testcase_29 AC 16 ms
9,144 KB
testcase_30 AC 17 ms
9,144 KB
testcase_31 AC 138 ms
9,144 KB
testcase_32 AC 67 ms
9,144 KB
testcase_33 AC 16 ms
9,144 KB
testcase_34 AC 16 ms
9,144 KB
testcase_35 AC 25 ms
9,144 KB
testcase_36 AC 50 ms
9,144 KB
testcase_37 AC 74 ms
9,144 KB
testcase_38 AC 114 ms
9,144 KB
testcase_39 AC 124 ms
9,144 KB
testcase_40 AC 116 ms
9,144 KB
testcase_41 AC 72 ms
9,144 KB
testcase_42 AC 100 ms
9,144 KB
testcase_43 AC 110 ms
9,144 KB
testcase_44 AC 104 ms
9,144 KB
testcase_45 AC 16 ms
9,144 KB
testcase_46 AC 66 ms
9,144 KB
testcase_47 AC 58 ms
9,148 KB
testcase_48 AC 72 ms
9,144 KB
testcase_49 AC 74 ms
9,144 KB
testcase_50 AC 65 ms
9,148 KB
testcase_51 AC 147 ms
9,148 KB
testcase_52 AC 62 ms
9,148 KB
testcase_53 AC 84 ms
9,148 KB
testcase_54 AC 145 ms
9,148 KB
testcase_55 AC 83 ms
9,148 KB
testcase_56 AC 85 ms
9,148 KB
testcase_57 AC 82 ms
9,148 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
const ll ILL=2167167167167167167;
const int INF=2100000000;
const int mod=998244353;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a,bool upp=0){if(a) cout<<(upp?"YES\n":"Yes\n"); else cout<<(upp?"NO\n":"No\n");}
template<class T> void vec_out(vector<T> &p,int ty=0){
if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'<<p[i]<<'"';}cout<<"}\n";}
else{if(ty==1){cout<<p.size()<<"\n";}for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}}
template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T vec_sum(vector<T> &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;}
int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;}

//Mobius(n)=0  exists p n|p*p
//         =-1  if n=p_1*p_2*...*p_{2a+1}
//         =1   if n=p_1*p_2*...*p_{2a}
std::vector<int> Mobius(int N){
    std::vector<int> p(N+1,-2);
    p[1]=1;
    for(int i=2;i<=N;i++){
        if(p[i]!=-2) continue;
        p[i]=-1;
        if(i<=5) p[i]=0;
        for(int j=i*2;j<=N;j+=i){
            if(p[j]==-2) p[j]=p[i];
            else p[j]*=p[i];
        }
        if(N/i<i) continue;
        for(int j=i*i;j<=N;j+=i*i) p[j]=0;
    }
    for(int i=1;i<=N;i++){
        if(p[i]==-2) p[i]=-1;
    }
    return p;
}


void solve();
// oddloop
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t=1;
    //cin>>t;
    rep(i,0,t) solve();
}

void solve(){
    ll L,N;
    cin>>L>>N;
    int D=42;
    vector<ll> p={2,3,5};
    ll Z=1001001;
    auto B=Mobius(Z);
    vector dp(D,vector(D,vector<ll>(D)));
    rep(i,0,N){
        ll a;
        cin>>a;
        vector<ll> q(3);
        rep(j,0,3) while(a%p[j]==0) q[j]++,a/=p[j];
        rep(j,0,8){
            auto r=q;
            rep(k,0,3) if(j&(1<<k)) r[k]++;
            dp[r[0]][r[1]][r[2]]++;
        }
    }
    ll ans=0;
    auto mul=[&](ll a,ll b) -> ll {
        if(ILL/b<=a) return ILL;
        return a*b;
    };
    vector C(D,vector(D,vector<ll>(D)));
    vector V(D,vector(D,vector<ll>(D)));
    C[0][0][0]=1;
    rep(i,0,D) rep(j,0,D) rep(k,0,D){
        if(i) C[i][j][k]=mul(C[i-1][j][k],2);
        if(j) C[i][j][k]=mul(C[i][j-1][k],3);
        if(k) C[i][j][k]=mul(C[i][j][k-1],5);
    }
    rep(i,0,D) rep(j,0,D) rep(k,0,D){
        if(dp[i][j][k]&1){
            vector<int> q={i,j,k};
            rep(l,0,8){
                auto tmp=q;
                int s=1;
                rep(r,0,3) if(l&(1<<r)) tmp[r]++,s*=-1;
                V[tmp[0]][tmp[1]][tmp[2]]+=s;
            }
        }
    }
    rep(i,0,D) rep(j,0,D) rep(k,0,D){
        if(V[i][j][k]==0) continue;
        ll X=C[i][j][k];
        rep(r,1,Z+1){
            ll tmp=mul(mul(X,r),r);
            if(tmp>L) break;
            ans+=B[r]*V[i][j][k]*(L/tmp);
        }
    }
    cout<<ans<<"\n";
}
0