Harry Potter and the Hide Story(hdu3988)
2016-10-01 12:35
417 查看
Harry Potter and the Hide Story
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 2809 Accepted Submission(s): 715
[align=left]Problem Description[/align]
iSea is tired of writing the story of Harry Potter, so, lucky you, solving the following problem is enough.
[align=left]Input[/align]
The first line contains a single integer T, indicating the number of test cases.
Each test case contains two integers, N and K.
Technical Specification
1. 1 <= T <= 500
2. 1 <= K <= 1 000 000 000 000 00
3. 1 <= N <= 1 000 000 000 000 000 000
[align=left]Output[/align]
For
each test case, output the case number first, then the answer, if the
answer is bigger than 9 223 372 036 854 775 807, output “inf” (without
quote).
[align=left]Sample Input[/align]
2
2 2
10 10
[align=left]Sample Output[/align]
Case 1: 1
Case 2: 2
思路:素数分解;
当K = 1的时候肯定输出inf;我们将n分解成素数的乘积,那么我们需要找m!分解后含有这些素数的个数cnt[pi],那么最高次就是min(cnt[pi]/cnt1[pi]);cnt1[pi]为n中pi的个数。
#include<stdio.h> #include<algorithm> #include<iostream> #include<queue> #include<set> #include<math.h> #include<string.h> using namespace std; typedef unsigned long long LL; bool prime[10000015]; LL ans[1000000]; LL prime_table[10000]; LL pr_cnt[10000]; LL pr_cn[10000]; LL slove(LL n,LL m,int cn); int main(void) { int T; scanf("%d",&T); int i,j; for(i = 2; i < 10000; i++) { if(!prime[i]) { for(j = i; (i*j) <= 10000010; j++) { prime[i*j] = true; } } } int cn = 0; for(i = 2; i < 10000010; i++) if(!prime[i])ans[cn++] = i; int __ca = 0; while(T--) { LL n,m; __ca++; scanf("%llu %llu",&m,&n); printf("Case %d: ",__ca); if(n == 1) printf("inf\n"); else { printf("%llu\n",slove(n,m,cn)); } } return 0; } LL slove(LL n,LL m,int cn) { int bn = 0; int f = 0; bool flag = false ; memset(pr_cnt,0,sizeof(pr_cnt)); memset(pr_cn,0,sizeof(pr_cn)); while(n>1) { while(n%ans[f]==0) { if(!flag) { flag = true; bn++; prime_table[bn] = ans[f]; } pr_cnt[bn]++; n/=ans[f]; } f++; flag = false; if((LL)ans[f]*(LL)ans[f] > n) break; } if(n > 1) { bn++; prime_table[bn] = n; pr_cnt[bn]++; }//printf("%d\n",n); LL maxx = -1; for(int i = 1; i <= bn; i++) { //printf("%llu\n",prime_table[i]); LL v = m; while(v) { v/=(LL)prime_table[i]; pr_cn[i]+=v; } if(maxx == -1) { maxx = (LL)pr_cn[i]/(LL)pr_cnt[i]; } else maxx = min((LL)pr_cn[i]/(LL)pr_cnt[i],maxx); } return maxx; }
相关文章推荐
- HDU3988 Harry Potter and the Hide Story
- HDU3988-Harry Potter and the Hide Story(数论-质因数分解)
- HDU3988-Harry Potter and the Hide Story(数论-质因数分解)
- HDU 3988 Harry Potter and the Hide Story (数论)
- [数论] hdu 3988 Harry Potter and the Hide Story
- hdu 3988 Harry Potter and the Hide Story
- HDU/HDOJ 3988 2011 WHU多校联合 Harry Potter and the Hide Story
- Harry Potter and the Hide Story HDU - 3988 (数论)
- 解题报告:HDU_3988 Harry Potter and the Hide Story 大素数分解+勒让德
- HDU 3988 Harry Potter and the Hide Story(数论-整数和素数)
- HDU 3988 Harry Potter and the Hide Story(数论-整数和素数)
- HDU 3988 Harry Potter and the Hide Story(数论)(素数筛法)
- HDU 3988 Harry Potter and the Hide Story
- HDU 3988 Harry Potter and the Hide Story(数论-整数和素数)
- HDU 3988 Harry Potter and the Hide Story(数论-整数和素数)
- HDU 3988-Harry Potter and the Hide Story(分解素数)
- hdu 3986 Harry Potter and the Final Battle 最短路spfa+枚举
- hdu 3986 Harry Potter and the Final Battle【最短路SPFA】
- HDU 3986 Harry Potter and the Final Battle Dijkstra + 堆优化
- hdu 3986 Harry Potter and the Final Battle