传送门
【题目分析】
。。。。突然不想写题解因为写不出来。。。。
感性理解+抄正解,然后因为一个溢出问了整个机房一圈。。。。。。蓝瘦。。。。。
直接贴代码吧。。。
【代码~】
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAXN=1e5+10;
LL n,tot;
LL c[MAXN],d[MAXN];
LL prime[MAXN],pri[MAXN],cnt,minpri[MAXN];
LL ans;
LL Read(){
LL i=0,f=1;
char c;
for(c=getchar();(c>'9'||c<'0')&&c!='-';c=getchar());
if(c=='-')
f=-1,c=getchar();
for(;c>='0'&&c<='9';c=getchar())
i=(i<<3)+(i<<1)+c-'0';
return i*f;
}
void pre(){
prime[1]=1;
for(LL i=2;i<MAXN;++i){
if(!minpri[i])
pri[++tot]=minpri[i]=i;
for(LL j=1;j<=tot;++j){
int k=i*pri[j];
if(k>1e5)
break;
minpri[k]=pri[j];
if(!(i%pri[j]))
break;
}
}
}
pair<LL,LL> find(int t){
LL a=1,b=1;
while(t^1){
int p=minpri[t],c=0;
while(!(t%p))
t/=p,++c;
c%=3;
if(c)
(c==1)?(a*=p, b*=p, b*=p):(a*=p, a*=p, b*=p);
}
return make_pair(a,b);
}
int main(){
pre();
n=Read();
for(LL i=1;i<=n;++i){
LL a=Read(),b=Read();
pair<LL,LL> x=find(a);
if(x.first==1)
ans=max(ans,b);
else{
if(x.first<x.second)
c[x.first]+=b;
else
d[x.second]+=b;
}
}
for(LL i=2;i<MAXN;++i)
ans+=max(c[i],d[i]);
cout<<ans;
return 0;
}