白书P171

对m,n!分解,质因子指数取min

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<sstream>
#include<vector>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
using namespace std;
const int maxn = 1e5+11;
typedef long long ll;
int n,m;
vector<int> p,k;
void chai(int n){
p.clear();k.clear();
int t=n;
for(int i=2;i*i<=n;i++){
if(t%i==0){
p.push_back(i);
k.push_back(1);
t/=i;
int pos=k.size()-1;
while(t%i==0){
k[pos]++;
t/=i;
}
}
}
if(t>1) p.push_back(t),k.push_back(1);
}
int main(){
int T,kase=0; cin>>T;
while(T--){
scanf("%d%d",&m,&n);
chai(m);
ll ans=1ll<<61;
for(int i=0;i<p.size();i++){
ll tmp=n,t=0;
while(tmp>1){
t+=tmp/p[i];
tmp/=p[i];
}
ans=min(t/k[i],ans);//not t!!!
}
cout<<"Case "<<++kase<<":"<<endl;
if(!ans) cout<<"Impossible to divide"<<endl;
else cout<<ans<<endl;
}
return 0;
}

UVA - 10780 唯一分解定理的更多相关文章

  1. UVa 1635 (唯一分解定理) Irrelevant Elements

    经过紫书的分析,已经将问题转化为求组合数C(n-1, 0)~C(n-1, n-1)中能够被m整除的个数,并输出编号(这n个数的编号从1开始) 首先将m分解质因数,然后记录下每个质因子对应的指数. 由组 ...

  2. UVa 10375 (唯一分解定理) Choose and divide

    题意: 求组合数C(p, q) / C(r, s)结果保留5为小数. 分析: 先用筛法求出10000以内的质数,然后计算每个素数对应的指数,最后再根据指数计算答案. #include <cstd ...

  3. UVA 10791 -唯一分解定理的应用

    #include<iostream> #include<stdio.h> #include<algorithm> #include<string.h> ...

  4. UVA - 11388 唯一分解定理

    题意:给出G和L,求最小的a使得gcd(a,b)=G,lcm(a,b)=L 显然a>=G,所以a取G,b要满足质因子质数为L的同次数,b取L //此处应有代码

  5. UVA - 10375 Choose and divide[唯一分解定理]

    UVA - 10375 Choose and divide Choose and divide Time Limit: 1000MS   Memory Limit: 65536K Total Subm ...

  6. UVA.10791 Minimum Sum LCM (唯一分解定理)

    UVA.10791 Minimum Sum LCM (唯一分解定理) 题意分析 也是利用唯一分解定理,但是要注意,分解的时候要循环(sqrt(num+1))次,并要对最后的num结果进行判断. 代码总 ...

  7. Irrelevant Elements UVA - 1635 二项式定理+组合数公式+素数筛+唯一分解定理

    /** 题目:Irrelevant Elements UVA - 1635 链接:https://vjudge.net/problem/UVA-1635 题意:給定n,m;題意抽象成(a+b)^(n- ...

  8. UVA 10375 Choose and divide【唯一分解定理】

    题意:求C(p,q)/C(r,s),4个数均小于10000,答案不大于10^8 思路:根据答案的范围猜测,不需要使用高精度.根据唯一分解定理,每一个数都可以分解成若干素数相乘.先求出10000以内的所 ...

  9. UVa 10791 Minimum Sum LCM【唯一分解定理】

    题意:给出n,求至少两个正整数,使得它们的最小公倍数为n,且这些整数的和最小 看的紫书--- 用唯一分解定理,n=(a1)^p1*(a2)^p2---*(ak)^pk,当每一个(ak)^pk作为一个单 ...

随机推荐

  1. OpenCV---resize

    转自http://www.cnblogs.com/korbin/p/5612427.html 在图像处理过程中,有时需要把图像调整到同样大小,便于处理,这时需要用到图像resize() 原函数void ...

  2. 数字图像处理实验(15):PROJECT 06-02,Pseudo-Color Image Processing 标签: 图像处理MATLAB 2017-05-27 20:53

    实验要求: 上面的实验要求中Objective(实验目的)部分是错误的. 然而在我拿到的大纲中就是这么写的,所以请忽视那部分,其余部分是没有问题的. 本实验是使用伪彩色强调突出我们感兴趣的灰度范围,在 ...

  3. Python3 Scrapy + Selenium + 阿布云爬取拉钩网学习笔记

    1 需求分析 想要一个能爬取拉钩网职位详情页的爬虫,来获取详情页内的公司名称.职位名称.薪资待遇.学历要求.岗位需求等信息.该爬虫能够通过配置搜索职位关键字和搜索城市来爬取不同城市的不同职位详情信息, ...

  4. PHP中 null ,false , 区别

    先来测试一下吧: if(0 ==''){ echo '<br/>在PHP中0 ==\'\'' ; } if(0 !==''){ echo '<br/>在PHP中0 !==\'\ ...

  5. hdu 4740 The Donkey of Gui Zhou

    1.扯犊子超多if else 判断的代码,华丽丽的TLE. #include<stdio.h> #include<string.h> #define N 1010 int ma ...

  6. Python基础-5

    目录 time &datetime模块 random os sys shutil json & picle shelve xml处理 yaml处理 hashlib re正则表达式 模块 ...

  7. 使用jQuery完成表单验证

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>注 ...

  8. java 支付宝即时到帐提交订单dome

    package com.tian.batis; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; imp ...

  9. angular 样式属性绑定

    <button (click)="onClick($event)">点我</button> <input type="> <ta ...

  10. SQL Server乱码处理(ASCII)

    CREATE FUNCTION [dbo].[RegexReplace] ( @string VARCHAR(MAX), --被替换的字符串 @pattern VARCHAR(255), --替换模板 ...