提交时间:2024-04-14 16:52:03

运行 ID: 28435

#include<bits/stdc++.h> #define up(i,l,r) for(int i=(l);i<=(r);++i) #define down(i,l,r) for(int i=(l);i>=(r);--i) #define p_b push_back #define p1 first #define p2 second using namespace std; typedef long long ll; const int maxn=1e6+10,mod=1e9+7; inline ll read(){ ll x=0;short t=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')t=-1;ch=getchar(); }while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x*t; } const int P[]={2,3,5,7,11,13,17,19}; const int d[]={8,5,3,3,2,2,2,2}; map<int,ll>mp[505]; ll MX; ll cal(ll M){ ll res=0; up(i,1,500)if(mp[i].size()){ ll s=0; for(auto it:mp[i])if(M%it.p1==0)s+=it.p2; if(s>0)res+=s; }return res; } void dfs(int x,ll M){ if(x>7){ MX=max(MX,cal(M));return; } ll g=1; up(i,0,d[x])dfs(x+1,M*g),g*=P[x]; } void slv(){ int n=read(); while(n--){ int x=read(),w=read(); int tmp=x; up(i,0,7)while(x%P[i]==0)x/=P[i]; mp[x][tmp/x]+=w; } dfs(0,1); cout<<MX; } int main(){ slv(); return 0; }