Treasure Hunting 分解质因子

来源:互联网 发布:如何查询淘宝买家信誉 编辑:程序博客网 时间:2024/06/02 07:16

Treasure Hunting

http://acm.hdu.edu.cn/showproblem.php?pid=3641

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 616    Accepted Submission(s): 200

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
123 24 1
 

 

Sample Output
6
Hint
n! is the factorial of number n:0!=1n!=n*(n-1)! (n>=1)a^0=1 (a>=1)a^i=a*(a^i-1) (i>=1)

 

x!%M=0,此题不需要用大数,也不用把M算出来,题目要求的是满足条件的最小的x。

分解M(i)的质因子,得到底数(质数)和指数。  枚举每一对底数和指数  返回一个x,最大的就是条件的值。而x!当然也包括了其它小的底数和指数  说得我也有点乱,举个例子:

1*2*3*4····*x    底数、指数是2 2      3  2   

2 2返回的结果是4       因为1-4里面 2能整除一个2 而4也能整除一个2  因此2个2都整除了。

3 2返回的结果是6       因为1-6里面 3能整除一个3 而6也能整除一个3  因此2个3都整除了。

最后结果就是6

底数、指数是2 2      3  3  返回的结果就是9

底数、指数是2 2      3  4  返回的结果也是9    因为9能整除2个3。。。。

原创粉丝点击