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的那块的面积占整个蛋糕的多少. 做法显而易见,就是一个半平 ...
随机推荐
- Error与Exception的区别
错误和异常的区别(Error vs Exception) 错误和异常的区别(Error vs Exception) 今天面试问了这样一个问题,"Error" 和 "Exc ...
- (40)JS运动之右下角悬浮框
<!DOCTYPE HTML> <!-- --> <html> <head> <meta charset="utf-8"> ...
- 提高SQL执行效率
原文地址:http://www.cnblogs.com/hlxs/archive/2012/05/07/2487082.html 1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 ...
- WPF动态改变主题颜色
原文:WPF动态改变主题颜色 国内的WPF技术先行者周银辉曾介绍过如何动态改变应用程序的主题样式,今天我们来介绍一种轻量级的改变界面风格的方式--动态改变主题色. 程序允许用户根据自己的喜好来对界面进 ...
- 动态接口服务 webservice
private void GetDll() { WebClient client = new WebClient(); string url = "http://xxxx/services/ ...
- TestThreadPoolExecutor.java
package ; import java.io.IOException;import java.io.InputStream;import java.util.List;impo ...
- Source not found for StandardEngine(ContainerBase).initInternal() line: 1078
总是这样 在复制完一个项目,并重新起了个名字后. 再打开网页就怎么也打开不了. 第一反应是tomcat出问题了. 于是有了这样的问题: Source not found for StandardE ...
- margin 还能够被缩回
<p><strong>话:</strong>的肥沃和收获而被估价的.才干也是土地,只是它生产的不是粮食,而是真理.假设仅仅能滋生瞑想和幻想的话,即使再大的才干也仅仅 ...
- python学习笔记之八:迭代器和生成器
一. 迭代器 在前面的笔记中,已经提到过迭代器(和可迭代),这里会对此进行深入讨论.只讨论一个特殊方法---__iter__,这个方法是迭代器规则的基础. 1.1 迭代器规则 迭代的意思是重复做一些事 ...
- J2SE基础:1.类和对象基础
什么是对象 在Java语言,全部的人,事物或者模块都是一个对象. 同样的对象具有一些同样的特性. 狗,猫,蛇3个对象(动物的对象) 苹果,梨,桔子3个对象(水果的对象) 什么是类 能够将现实生活中的对 ...