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 模拟队列(一般队列、双端队列、优先级队列)
队列: 先进先出,处理类似排队的问题,先排的.先处理,后排的等前面的处理完了,再处理 对于插入和移除操作的时间复杂度都为O(1).从后面插入,从前面移除 双端队列: 即在队列两端都能够insert和r ...
- android
在特殊应用的特殊功能,以帮助通信系统的问题
在实际工程中的应用,进入一个特殊的应用后,系统的某个功能不能起作用. 当然,这个通信有非常多办法能够做到.笔者能够想到的至少有例如以下几种 1.利用property熟悉来实现,这种话须要添加一个特殊的 ...
- [ACM] hdu 4418 Time travel (高斯消元求期望)
Time travel Problem Description Agent K is one of the greatest agents in a secret organization calle ...
- SE 2014年5月6日
如图配置: 三台交换机两两相连接,构成一二层环路,同时为了保证链路的较为可靠,使用双线链接 请用自己的语言描述以上拓扑搭建的优劣势:并使用哪些技术较为合理,请描述并实施 SW3为接入层交换机,下链接三 ...
- 用xml建立仓库的逻辑层的操作
package com.repositoryclient.xml; import java.io.FileNotFoundException; import java.io.FileOutputStr ...
- Oracle语句集锦
创建用户并赋予dba权限 1)进入cmd 2)sqlplus / as sysdba 或者 sqlplus sys/密码 as sysdba SQL> conn sys/wcq123@orcl ...
- ecshop首页调用指定分类的所有产品(指定一级调二级)
第一种方法 第一 在/includes/lib_goods.php下增加如下代码,用过网上的直接换掉就可以 function index_get_cat_id_goods_best_list($cat ...
- Multitasking Apps may only use background services for their intended purposes
2.16 Details Your app declares support for audio in the UIBackgroundModes key in your Info.plist, bu ...
- Web Worker在WebKit中的实现机制
web worker 是执行在后台的 JavaScript,独立于其它脚本.不会影响页面的性能.这是HTML5的一个标准:实现上讲.浏览器为wokrer启动了新的线程,从而实现了异步操作的功能; 以下 ...
- 使用JS或jQuery模拟鼠标点击a标签事件代码
原文 使用JS或jQuery模拟鼠标点击a标签事件代码 这篇文章主要介绍了使用JS或jQuery模拟鼠标点击a标签事件代码,需要的朋友可以参考下 <a id="alink" ...