hdu Treasure Hunting 求最少的X使得X!%m=0

Treasure Hunting

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Problem Description
Zstu_yhr is a very curious person who fell in love with math when he was in elementary school phase. When he entered the middle school, he learned Multiplication and Power Multiplication. yhr is so ambitious that he not only dreams to be a mathematician but also dreams to be richer than Bill Gates.
One day, he is suddenly encountered with a crazy thought that is to hunt treasure to make one of his dreams a reality. Since yhr is such a strong-willed person that he will never give up as long as his goal has not been achieved. After going through 9*9 challenges, as a reward of god for that hard, he finally discovers an antique hole which is very likely to have a good number of treasures in it. However, as every novel writes, he can never get the treasures so easily. He has to open a coded door at first. He finds that there are 2*N numbers on the door. He speculates that they must be able to generate the password. Disappointedly, there isn’t any clue left for him. He has no better way but to YY. Firstly, he divides these 2*N number into N piles equally. The first pile is composed of a1,b1 and the second pile is composed of a2,b2...certainly, the i-th pile is composed of ai,bi…After completing this task, he calculates a1^b1*a2^b2*a3^b3…*an^bn and gets its result M. He takes M as the password to open the door. What’s a pity, he fails. Then he starts to YY again. Maybe the right password is the minimum number x which satisfies the equation x!%M=0. So he wants to have a try. But he doesn’t know how to get the number so that he has to turn to you for help. Can you help him?
 

 

Input
In the first line is an integer T (1<=T<=50) indicating the number of test cases.
Each test case begins with an integer n (1<=n<=100), then followed n lines. Each line contains two numbers ai and bi (1 <= ai <= 100, 1<=bi<=10000000000000)
 

 

Output
For each test case output the result x in one line.
 

 

Sample Input
  
  
1 2 3 2 4 1
 

 

Sample Output
  
  
6
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int prime[110],is[110],pl;
__int64 cnt[110];
void _prime()
{
    for(int i=2;i<110;i++)
    {
        if(is[i]==0) prime[pl++]=i;
        for(int j=0;j<pl&&i*prime[j]<110;j++)
        {
            is[i*prime[j]]=1;
            if(i%prime[j]==0) break;
        }
    }
}
__int64 _pow(int x,int y)
{
    if(y==0) return 1;
    if(y==1) return x;
    __int64 temp=_pow(x,y/2);
    temp=temp*temp;
    if(y&1) temp*=x;
    return temp;
}
__int64 _Count(__int64 n,int x)
{
    __int64 cnt=0;
    while(n)
    {
        cnt+=n/x;
        n/=x;
    }
    return cnt;
}
int main()
{
    _prime();
    int ci;scanf("%d",&ci);
    while(ci--)
    {
        __int64 ans=0;
        memset(cnt,0,sizeof(cnt));
        int m;scanf("%d",&m);
        while(m--)
        {
            int x;__int64 y;scanf("%d%I64d",&x,&y);
            for(int i=0;i<pl&&prime[i]*prime[i]<=x;i++)
            {
                if(x%prime[i]==0)
                {
                    int t=0;
                    while(x%prime[i]==0) t++,x/=prime[i];
                    cnt[prime[i]]+=t*y;
                }
            }
            if(x>1) cnt[x]+=y;
        }
        for(int i=2;i<110;i++)
        {
            if(cnt[i])
            {
                int k=1;
                for(;;k++)
                {
                    __int64 sum=(_pow(i,k)-1)/(i-1);
                    if(sum>cnt[i]) break;
                }k--;
                __int64 l=_pow(i,k),r=l*i,t=l;
                while(l<r)
                {
                    __int64 mid=(l+r)>>1;
                    if(_Count(mid,i)<cnt[i]) l=mid+1;
                    else r=mid;
                }
                if(l>ans) ans=l;
            }
        }
        printf("%I64d/n",ans);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值