HDU3988-Harry Potter and the Hide Story(数论-质因数分解)
Harry Potter and the Hide Story
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2193 Accepted Submission(s): 530

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
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std; #define LL unsigned long long const int maxn = 10000005;
bool isPrime[maxn];
vector<LL> prime,digit,cnt; void getPrime(){
prime.clear();
memset(isPrime,0,sizeof isPrime);
for(LL i = 2; i < maxn; i++){
if(!isPrime[i]){
prime.push_back(i);
for(LL j = i*i; j < maxn; j += i)
isPrime[j] = 1;
}
}
} void getDigit(LL k){ for(int i = 0; i < prime.size() && k >= prime[i]; i++){
if(k%prime[i]==0){
int tt = 0;
digit.push_back(prime[i]);
while(k%prime[i]==0){
tt++;
k /= prime[i];
}
cnt.push_back(tt);
}
}
if(k!=1){
digit.push_back(k);
cnt.push_back(1);
}
} LL getSum(LL n,LL p){
LL res = 0;
while(n){
n /= p;
res += n;
}
return res;
}
int main(){
int ncase,T=1;
LL k,n;
getPrime();
cin >> ncase;
while(ncase--){
cin >> n >> k;
if(k==1){
printf("Case %d: inf\n",T++);
continue;
}
LL ans = -1;
digit.clear();
cnt.clear();
getDigit(k); for(int i = 0; i < digit.size(); i++){
LL tk = getSum(n,digit[i])/cnt[i];
if(ans == -1) ans = tk;
else ans = min(ans,tk);
}
printf("Case %d: %I64u\n",T++,ans); }
return 0;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。
HDU3988-Harry Potter and the Hide Story(数论-质因数分解)的更多相关文章
- UVA 10892 LCM Cardinality(数论 质因数分解)
LCM Cardinality Input: Standard Input Output: Standard Output Time Limit: 2 Seconds A pair of number ...
- HDU 3988 Harry Potter and the Hide Story(数论-整数和素数)
Harry Potter and the Hide Story Problem Description iSea is tired of writing the story of Harry Pott ...
- Harry Potter and the Hide Story(hdu3988)
Harry Potter and the Hide Story Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 ...
- 数学概念——J - 数论,质因数分解
J - 数论,质因数分解 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- 简单数论之整除&质因数分解&唯一分解定理
[整除] 若a被b整除,即a是b的倍数,那么记作b|a("|"是整除符号),读作"b整除a"或"a能被b整除".b叫做a的约数(或因数),a ...
- Pairs Forming LCM (LightOJ - 1236)【简单数论】【质因数分解】【算术基本定理】(未完成)
Pairs Forming LCM (LightOJ - 1236)[简单数论][质因数分解][算术基本定理](未完成) 标签: 入门讲座题解 数论 题目描述 Find the result of t ...
- Leetcode 263 Ugly Number 数论 类似质因数分解
Ugly Number的质因数仅为2,3,5 将输入的数分别除以2,3,5直到不能除,看是否为1,为1的是Ugly Number,其他则不是. class Solution { public: boo ...
- hdu 5108(数论-整数分解)
Alexandra and Prime Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (J ...
- 集训第六周 数学概念与方法 J题 数论,质因数分解
Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all g ...
随机推荐
- mysql 开放的telnet
两步开幕mysql远程连接 一个,登录mysql # mysql -uroot -p 两,配置远程连接 mysql > GRANT ALL PRIVILEGES ON *.* TO 'user1 ...
- 如何检测被锁住的Oracle存储过程及处理办法汇总(转)
1.查看是哪一个存储过程被锁住查V$DB_OBJECT_CACHE视图select * from V$DB_OBJECT_CACHE where owner='过程的所属用户' AND LOCKS!= ...
- Android中Dialog的使用
上一篇博文讲到对话框popWindow的使用,这篇博文主要解说Dialog的使用. 1.什么是Dialog? Dialog就是对话框的一种方式! 在Android开发中.我们常常会须要在Android ...
- The JSR-133 Cookbook for Compiler Writers(an unofficial guide to implementing the new JMM)
The JSR-133 Cookbook for Compiler Writers by Doug Lea, with help from members of the JMM mailing lis ...
- 经常使用的js小方法
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <% Strin ...
- Storm On YARN带来的好处
1)弹性计算资源 将storm执行在yarn上后.Storm能够与其它计算框架(如mapreduce)共享整个集群的资源.这样当Storm负载骤增时,可动态为它添加计算资源. 负载减小时,能够 ...
- Linux学习记录--命名管道通信
命名管道通信 什么是命名管道 一个主要的限制是,它是匿名管道的应用还没有名字,因此,只有它可以用于进程间通信的方式与亲缘关系.在命名管道(named pipe或FIFO)提出后,该限制得到了克服.FI ...
- DFA和trie特里实现敏感词过滤(python和c语言)
今天的项目是与完成python开展,需要使用做关键词检查,筛选分类,使用前c语言做这种事情.有了线索,非常高效,内存小了,检查快. 到达python在,第一个想法是pip基于外观的c语言python特 ...
- 乐在其中设计模式(C#) - 状态模式(State Pattern)
原文:乐在其中设计模式(C#) - 状态模式(State Pattern) [索引页][源码下载] 乐在其中设计模式(C#) - 状态模式(State Pattern) 作者:webabcd 介绍 允 ...
- T-SQL中default值的使用
今天介绍一下通过T-SQL语句来创建表时使用default的关键字来自动使用默认值,这个关键字和其它的如:identity,primary key ,not null ,unique等不是相同,这里简 ...