HDU 3988 Harry Potter and the Hide Story(数论-整数和素数)
来源:互联网 发布:读书郎软件下载 编辑:程序博客网 时间:2024/04/30 04:49
Harry Potter and the Hide Story
Problem Description
iSea is tired of writing the story of Harry Potter, so, lucky you, solving the following problem is enough.
Input
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
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
Output
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).
Sample Input
22 210 10
Sample Output
Case 1: 1Case 2: 2
Author
iSea@WHU
Source
2011 Multi-University Training Contest 15 - Host by WHU
Recommend
lcy | We have carefully selected several similar problems for you: 3987 3986 3983 3984 3985
给定 n和k , 求 n! % k^i 等于0时,i 的最大取值是多少?
解题思路:
将 k分解质因素,n也根据k的质因素求出关系限制i,最后算出最大的i即可。
解题代码:
#include <iostream>#include <cstdio>#include <map>#include <vector>#include <cstring>using namespace std;typedef unsigned long long ll;ll n,k;const int maxn=10000010;bool isPrime[maxn];vector <ll> v;ll tol;void get_prime(){ tol=0; memset(isPrime,true,sizeof(isPrime)); for(ll i=2;i<maxn;i++){ if(isPrime[i]){ tol++; v.push_back(i); } for(ll j=0;j<tol && i*v[j]<maxn;j++){ isPrime[i*v[j]]=false; if(i%v[j]==0) break; } } //for(ll i=v.size()-1;i>=v.size()-100;i--) cout<<v[i]<<endl;}map <ll,ll> getPrime(ll x){ map <ll,ll> mp; for(ll i=0;i<tol && x>=v[i];i++){ while(x>0 && x%v[i]==0){ x/=v[i]; mp[v[i]]++; } } if(x>1) mp[x]++; return mp;}void solve(){ if(k==1){ printf("inf\n"); return; } map <ll,ll> mp=getPrime(k); ll ans=1e19; for(map <ll,ll>::iterator it=mp.begin();it!=mp.end();it++){ ll tmp=n,sum=0; while(tmp>0){ sum+=tmp/(it->first); tmp/=(it->first); } if(sum/(it->second)<ans) ans=sum/(it->second); } cout<<ans<<endl;}int main(){ get_prime(); int t; scanf("%d",&t); for(int i=0;i<t;i++){ cin>>n>>k; printf("Case %d: ",i+1); solve(); } return 0;}
2 0
- 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(分解素数)
- Harry Potter and the Hide Story HDU
- hdu 3988 Harry Potter and the Hide Story
- HDU 3988 Harry Potter and the Hide Story
- HDU 3998 Harry Potter and the Hide Story【数学】
- HDU3988-Harry Potter and the Hide Story(数论-质因数分解)
- HDU3988 Harry Potter and the Hide Story
- HDU/HDOJ 3988 2011 WHU多校联合 Harry Potter and the Hide Story
- 解题报告:HDU_3988 Harry Potter and the Hide Story 大素数分解+勒让德
- 多校15场Harry Potter and the Hide Story(合数分解)
- HDU 3987 Harry Potter and the Forbidden Forest 最小割
- hdu 3986 Harry Potter and the Final Battle
- HDU 3986 Harry Potter and the Final Battle
- DP优化——四边形不等式(简介)
- java中的char
- 从官网下载STM32固件函数库
- Linux 多核下绑定硬件中断到不同 CPU(IRQ Affinity)
- 产品经理的主要工作职责
- HDU 3988 Harry Potter and the Hide Story(数论-整数和素数)
- python比较2个xml内容
- 2013计算机视觉代码合集(一、二)
- vs2012 安装后 出现的一种问题 关于 .net framework
- C 使用异或(xor)加密/解密文件
- javascript 提取身份证的生日和性别
- Remove Duplicates from Sorted Array
- robotium自动化测试简介
- 区分shapefile,coverage,geodatabase