脑洞题。。。
我写的有点麻烦...
显然质数肯定是个奇数,那么对于质数p,他下一次肯定变成了2*x...
然后如果一开始没有2,那么次数要+1,因为第一次不会消去2,之后每一次都至少会有一个2可以消去.
实际答案就是最后化下来的num[2]
c++代码如下:
#include<bits/stdc++.h>
#define rep(i,x,y) for(register int i = x;i <= y ;++ i)
#define repd(i,x,y) for(register int i = x;i >= y ;-- i)
using namespace std;
typedef long long ll;
template<typename T>inline void read(T&x)
{
x = 0;char c;int sign = 1;
do { c = getchar(); if(c == '-') sign = -1; }while(!isdigit(c));
do { x = x * 10 + c - '0'; c = getchar(); }while(isdigit(c));
x *= sign;
}
const int N = 1e5+50;
int prime[N],s[N],cnt;
bool vis[N];
inline void pre()
{
int m = N - 50;
rep(i,2,m)
{
if(!vis[i]) prime[++cnt] = i;
for(register int j = 1; i * prime[j] <= m;++ j)
{
vis[i * prime[j]] = 1;
if(i % prime[j] == 0)
{
s[i * prime[j]] = prime[j];
break;
}
s[i * prime[j]] = prime[j];
}
}
}
int m;ll ans,num[N];
inline void solve()
{
ans = 1;
read(m);
rep(i,1,m)
{
int p,q;
read(p); read(q);
num[p] += q;
}
if(num[2] == 0) num[2] = 1;
repd(i,N - 50,2)
if(num[i]){
if(vis[i])
{
num[s[i]] += num[i];
num[i / s[i]] += num[i];
}
else
{
ans = max(num[i],ans);
num[i - 1] += num[i];
}
num[i] = 0;
}
printf("%lld\n",ans);
}
int main()
{
int t;
pre();
read(t);
while(t--)
solve();
return 0;
}