HDU 3988 Harry Potter and the Hide Story(数论-整数和素数)
Harry Potter and the Hide Story

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
2
2 2
10 10
Case 1: 1
Case 2: 2
pid=3983" target="_blank" style="color:rgb(26,92,200); text-decoration:none">3983
pid=3984" target="_blank" style="color:rgb(26,92,200); text-decoration:none">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;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
HDU 3988 Harry Potter and the Hide Story(数论-整数和素数)的更多相关文章
- HDU3988-Harry Potter and the Hide Story(数论-质因数分解)
Harry Potter and the Hide Story Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 ...
- Harry Potter and the Hide Story(hdu3988)
Harry Potter and the Hide Story Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 ...
- HDU 3987 Harry Potter and the Forbidden Forest(边权放大法+最小割)
Harry Potter and the Forbidden Forest Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/ ...
- hdu 3986 Harry Potter and the Final Battle (最短路径)
Harry Potter and the Final Battle Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65536/6553 ...
- hdu 3987 Harry Potter and the Forbidden Forest 求割边最少的最小割
view code//hdu 3987 #include <iostream> #include <cstdio> #include <algorithm> #in ...
- 【Dijstra堆优化】HDU 3986 Harry Potter and the Final Battle
http://acm.hdu.edu.cn/showproblem.php?pid=3986 [题意] 给定一个有重边的无向图,T=20,n<=1000,m<=5000 删去一条边,使得1 ...
- hdu 3986 Harry Potter and the Final Battle
一个水题WA了60发,数组没开大,这OJ也不提示RE,光提示WA...... 思路:先求出最短路,如果删除的边不是最短路上的,那么对结果没有影响,要有影响,只能删除最短路上的边.所以枚举一下最短路上的 ...
- HDU Stealing Harry Potter's Precious(状压BFS)
状压BFS 注意在用二维字符数组时,要把空格.换行处理好. #include<stdio.h> #include<algorithm> #include<string.h ...
- hdu 3982 Harry Potter and J.K.Rowling (半平面交 + 圆与多边形交)
Problem - 3982 题意就是给出一个圆心在原点半径为R的圆形蛋糕,上面有一个cherry,对蛋糕切若干刀,最后要求求出有cherry的那块的面积占整个蛋糕的多少. 做法显而易见,就是一个半平 ...
随机推荐
- 【Java&Android开源库代码剖析】のAndroid-Universal-Image-Loader-part1
做Android app开发的同学应该都听说过或者用过nostra13的Android-Universal-Image-Loader开源库,它在图片异步加载.缓存和显示等方面提供了强大灵活的框架.之前 ...
- HDU 5071 Chat
题意: CLJ找了很多妹子- (题目好没节操-) 对于CLJ和妹子的聊天对话框 有一下几种操作: add 加一个妹子在聊天窗队列末尾 假设这个妹子已经在队列中则add失败 close 关掉 ...
- jQuery Mobile 是创建移动 web 应用程序的框架。
jQuery Mobile jQuery Mobile 是创建移动 web 应用程序的框架. jQuery Mobile 适用于所有流行的智能手机和平板电脑. jQuery Mobile 使用 HTM ...
- 从mina中学习超时程序编写
从mina中学习超时程序编写 在很多情况下,程序需要使用计时器定,在指定的时间内检查连接过期.例如,要实现一个mqtt服务,为了保证QOS,在服务端发送消息后,需要等待客户端的ack,确保客户端接收到 ...
- 后台使用oracle前台使用easyui分页机制
前台easyui 的datagrid中设置分页属性: pagination:true,//显示分页 pagePosition:'bottom',//分页栏位置 both 上下 bottom.top p ...
- JS经常使用正則表達式【分享】
工作中JS经常使用表达式: 1)2010-09-10类型日期校验 2)推断正整数.字符串长度 3)校验长度,和是否空 4)推断字符串是否为空 5)比較字符大小 6)推断字符串长度 7)推断格式是否为E ...
- 可兼容IE的jquery.cookie函数方法
前言 在开发过程中,因为之前有接触过Discuz,就直接拿其common.js里面的getcookie和setcookie方法来使用,做到后面在使用IE来测试的时候,发现这两个方法子啊IE下不起作用, ...
- Sql SUBSTR函数
SUBSTR( ) 从一个字符表达式或备注字段中返回一个字符串.该字符串起始于字符表达式或备注字段的指定位置,到指定数目字符结束. 例如: SUBSTR(“A1”, 1 1]) 结果:A
- sgu 286. Ancient decoration(最小环覆盖)
给你一个n个点,每个点度为k(k为偶数)的无向图,问是否能将图中的n条边染色,使得每个点都拥有两条被染色的边.也就是说,是否存在拥有原图中n条边的子图,使得每个点的度为2?仔细想想,每个点的度为2,实 ...
- VS2010关于error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
前段时间自己的系统一直在安装更新.今天突然打开VS2010当运行的时候一直出现error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏这种错误.然后就百度 解决的方法: 1.项目\属 ...