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 ...
随机推荐
- LeetCode——Valid Sudoku
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules. The Sudoku board could be ...
- Android系统各版本号及代号
Android系统各版本号及代号 版本 版本号代号 公布日期 API Android 1.0 阿童木 1 Android 1.1 发条机器人 2008.9 2 Android 1.5 纸杯蛋糕 200 ...
- hdu1500 (排序+单调队列优化 )
从n根筷子里面, 选择k+8个集合的筷子,每个集合三根筷子, A<=B<=C, 费用是(A-B)^2, 问最小的费用是多少. 将n根筷子排序之后,可以知道A和B的下标一定是连续的. 比如有 ...
- 黑马day07 注册案例(二)
1依据index.jsp我们首先制定了注册的功能,当点击注册button什么时候.超链接到注册页面.下面是一个注册jsp页 <%@ page language="java" ...
- 判断DAG图
拓扑排序O(E), bellman O(VE) , 使用邻接表的dfs O(V+E) ,floyd O(N*N*N) bellman算法只能判断是否存在负环. 所以可以先把权值全部设为-1 #in ...
- linux 流量监控 ---iptraf的安装及使用
一.安装iptraf 我用的是centos,切换到root用户,执行 yum install -y iptraf 二.使用 1.直接输入iptraf,进入软件,按任意键继续 2.我主要是第二项和第三项 ...
- URAL 1934 Black Spot --- 最短的简单修改
右侧是1.维护的同时保持最短路p值至少,我有直接存款(1-p).该概率不满足,为了使这个值极大. #include <iostream> #include <cstdlib> ...
- Android开发调节屏幕亮度
在播放器,我们经常看到这样的设计,即,在用户的特定部分将能够滑动屏幕向上或向下调整屏幕的亮度,上下滑动的某一部分将能够调整播放音量.并以滑动的进程可以进行调整,以玩. 如今,我不得不说一下亮度调节. ...
- Android SVN开发实战的文件夹结构呈现
svn有一个非常标准的文件夹结构,这是. 例如,该项目是proj.svn地址svn://proj/,然后该标准svn布局是 svn://proj/ | +-trunk +-branches +-tag ...
- 冷市攻略:Listo 教你 25 今天的社会 Swift 语言 - 02 Swift Tour
import Foundation //******************************************************************************** ...