HDU/HDOJ 3641 Treasure Hunting 2010年杭州赛区网络赛
2011-09-01 17:07
375 查看
Treasure Hunting
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 985 Accepted Submission(s): 316
[align=left]Problem Description[/align]
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?
[align=left]Input[/align]
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)
[align=left]Output[/align]
For each test case output the result x in one line.
[align=left]Sample Input[/align]
1 2 3 2 4 1
[align=left]Sample Output[/align]
6 Hint n! is the factorial of number n: 0!=1 n!=n*(n-1)! (n>=1) a^0=1 (a>=1) a^i=a*(a^i-1) (i>=1)
[align=left]Source[/align]
The 35th ACM/ICPC Asia Regional Hangzhou Site —— Online Contest
一年前,实力很弱,居然想到了取对数神马玄乎又玄的东西。
昨天跑去重新做了下,发现原来是个水题,可以直接二分答案计算出来
解法:
把所有的ai进行一个质因数分解,然后二分答案,判断当前的mid值的阶乘是否能够整除M
我的代码:
#include<stdio.h> #include<algorithm> #include<string.h> #include<vector> using namespace std; typedef __int64 ll; ll num[105]; ll a[105],b[105]; ll n; void solve(ll N,ll th) { int i,cnt; for(i=2;i*i<=N;i++) { cnt=0; if(N%i==0) { N=N/i; cnt++; while(N%i==0) { N=N/i; cnt++; } num[i]=num[i]+cnt*th; } if(N==1) break; } if(N>1) num =num +th; } ll cal(ll x,ll N) { ll ret=0; while(N) { N=N/x; ret=ret+N; } return ret; } bool judge(ll x) { ll i,temp; for(i=1;i<=100;i++) { if(num[i]>0) { temp=cal(i,x); if(temp<num[i]) return false; } } return true; } void init() { memset(num,0,sizeof(num)); } int main() { ll i,t,left,right,mid,ans; scanf("%I64d",&t); while(t--) { scanf("%I64d",&n); init(); for(i=1;i<=n;i++) { scanf("%I64d%I64d",&a[i],&b[i]); solve(a[i],b[i]); } left=0,right=1000000000000000000ll; while(left<=right) { mid=(left+right)>>1; if(judge(mid)) { right=mid-1; ans=mid; } else { left=mid+1; } } printf("%I64d\n",ans); } return 0; }
相关文章推荐
- HDU/HDOJ 3714 Error Curves 2010年成都赛区
- HDU/HDOJ 4038 2011成都赛区网络赛H题
- HDU/HDOJ 4004 2011大连赛区网络赛 D题
- HDU/HDOJ 4002 2011大连赛区网络赛 数论
- HDU 4417 Super Mario 第37届ACM/ICPC 杭州赛区网络赛1008题(树状数组或者线段树)
- 2013年ACM网络赛杭州赛区
- HDOJ 5012 Dice--2014网络赛西安赛区F题
- 2014亚洲区域赛网络赛广州赛区A Corrupt Mayor's Performance Art(hdoj5023)
- 2012 ACM/ICPC 杭州赛区网络赛Super Mario
- 2011大连赛区网络赛 HDOJ
- POJ 3696 HDU/HDOJ 2462 2008年合肥赛区
- [2010杭州赛区网络赛1006]Fate Stay
- HDU/HDOJ 3592 差分约束 World Exhibition 2010年多校联合第15场
- Hiking Trip 08年杭州赛区网络预选赛
- hdu 4411 2012杭州赛区网络赛 最小费用最大流 ***
- HDU4415 Assassin’s Creed 2012ACM/ICPC 杭州赛区网络赛 F
- To Be an Dream Architect(2010年ACM亚洲预选赛杭州赛区第三题))
- "虹软杯" 中国大学生程序设计竞赛 (杭州赛区)-网络赛水题题解
- hdu 4741 2013杭州赛区网络赛 dfs ***
- hdu 4412 2012杭州赛区网络赛 期望