提交时间:2024-04-14 15:05:44

运行 ID: 28386

#include <bits/stdc++.h> using namespace std; //#define int long long //#define endl "\n" int m[510],v[510]; int n; int s[70003]; vector<int>P={2,3,5,7,11,13,17,19}; const int p=8; map<int,int>mp; int cnt=0; inline void dfs(int dep,int prod){ // cout<<dep<<" "<<prod<<endl; if(dep==p){ mp[prod]=++cnt; s[cnt]=prod; return ; } int ct=1; while(ct<=500){ dfs(dep+1,prod*ct); ct*=P[dep]; } } int ID[510]; int f[70000]; int g[70000][100]; inline bool chk(int x){ for(int i=2;i*i<=x;i++) if(x%i==0)return 0; return 1; } signed main(){ ios::sync_with_stdio(0); // freopen("sequence.in","r",stdin); // freopen("sequence.out","w",stdout); dfs(0,1); cin>>n; int pp=0; for(int i=21;i<=500;i++) if(chk(i)) ID[i]=++pp; for(int i=1;i<=n;i++){ int x,v,w; cin>>x>>v; w=1; for(int p:P)while(x%p==0)x/=p,w*=p; for(int i=1;i<=cnt;i++) if(s[i]%w==0){ if(x==1)f[i]+=v; else g[i][ID[x]]+=v; } } int res=0; for(int i=1;i<=cnt;i++){ int ct=f[i]; // if(ct)cout<<i<<" "<<s[i]<<" "<<f[i]<<endl; for(int j=1;j<=pp;j++)ct+=max(g[i][j],0); res=max(res,ct); } cout<<res<<endl; cout.flush(); fflush(stdout); return 0; }