C. Trailing Loves (or L'oeufs?) (质因数分解)
C. Trailing Loves (or L'oeufs?)
题意:
求n!在b进制下末尾有多少个0?
思路:
类比与5!在10进制下末尾0的个数是看2和5的个数,那么
原题就是看b进行质因数分解后,每个因数个数的最小值
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 1000005
ll pri[N];
ll cnt[N];
ll tot;
void getpri(ll x)
{
memset(cnt,,sizeof(cnt));
memset(pri,,sizeof(pri));
for(ll i=;i*i<=x;i++)
{
while(x%i==)
{
pri[tot]=i;
cnt[tot]++;
x/=i;
}
if(cnt[tot]) tot++;
}
if(x>) pri[tot]=x,cnt[tot++]++;
}
ll solve(ll x,ll p)
{
ll res=;
while(x)
{
res+=x/p;
x/=p;
}
return res;
}
int main()
{
ll n,b;
while(~scanf("%lld %lld",&n,&b)){
tot=;
getpri(b);
ll maxn=1e18;
/*for(int i=0;i<tot;i++)
cout<<pri[i]<<" "<<cnt[i]<<endl;*/
for(ll i=;i<tot;i++)
{
maxn=min(maxn,solve(n,pri[i])/cnt[i]);
}
printf("%lld\n",maxn);
} return ;
}
C. Trailing Loves (or L'oeufs?) (质因数分解)的更多相关文章
- CF 1114 C. Trailing Loves (or L'oeufs?)
C. Trailing Loves (or L'oeufs?) 链接 题意: 问n!化成b进制后,末尾的0的个数. 分析: 考虑十进制的时候怎么求的,类比一下. 十进制转化b进制的过程中是不断mod ...
- CF#538(div 2) C. Trailing Loves (or L'oeufs?) 【经典数论 n!的素因子分解】
任意门:http://codeforces.com/contest/1114/problem/C C. Trailing Loves (or L'oeufs?) time limit per test ...
- Codeforces - 1114C - Trailing Loves (or L'oeufs?) - 简单数论
https://codeforces.com/contest/1114/problem/C 很有趣的一道数论,很明显是要求能组成多少个基数. 可以分解质因数,然后统计各个质因数的个数. 比如8以内,有 ...
- 【Codeforces 1114C】Trailing Loves (or L'oeufs?)
[链接] 我是链接,点我呀:) [题意] 问你n!的b进制下末尾的0的个数 [题解] 证明:https://blog.csdn.net/qq_40679299/article/details/8116 ...
- CF#538 C - Trailing Loves (or L'oeufs?) /// 分解质因数
题目大意: 求n!在b进制下末尾有多少个0 https://blog.csdn.net/qq_40679299/article/details/81167283 一个数在十进制下末尾0的个数取决于10 ...
- Codeforces Round #538 (Div. 2) C. Trailing Loves (or L'oeufs?) (分解质因数)
题目:http://codeforces.com/problemset/problem/1114/C 题意:给你n,m,让你求n!换算成m进制的末尾0的个数是多少(1<n<1e18 ...
- Trailing Loves (or L'oeufs?)
The number "zero" is called "love" (or "l'oeuf" to be precise, literal ...
- C. Trailing Loves (or L'oeufs?)
题目链接:http://codeforces.com/contest/1114/problem/C 题目大意:给你n和b,让你求n的阶乘,转换成b进制之后,有多少个后置零. 具体思路:首先看n和b,都 ...
- Trailing Loves (or L'oeufs?) CodeForces - 1114C (数论)
大意: 求n!在b进制下末尾0的个数 等价于求n!中有多少因子b, 素数分解一下, 再对求出所有素数的最小因子数就好了 ll n, b; vector<pli> A, res; void ...
随机推荐
- 2018-2-13-win10-uwp-参考
title author date CreateTime categories win10 uwp 参考 lindexi 2018-2-13 17:23:3 +0800 2018-2-13 17:23 ...
- Maya多版本下载与激活方法
目录 1. 安装激活说明 1. 安装激活说明 Maya2019:https://www.cnblogs.com/coco56/p/11425559.html Maya2017:https://www. ...
- linux测试 Sersync 是否正常
[root@SERSYNC web]# for i in {1..10000};do echo 123456 > /data/web/$i &>/dev/null;do ne [r ...
- python如何查看内存占用空间
我们如何查看变量占用了多少内存空间呢 首先我们引用sys模块,在使用getsizeof()方法 import sys L = [x for x in range(10000)] print(sys.g ...
- [洛谷P1514] NOIP2010 引水入城
问题描述 在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠.该国的行政区划十分特殊,刚好构成一个N 行×M 列的矩形,如上图所示,其中每个格子都代表一座城市,每座城市都有一个海拔高度. ...
- LightOJ 1079 Just another Robbery (01背包)
题目链接 题意:Harry Potter要去抢银行(wtf???),有n个银行,对于每个银行,抢的话,能抢到Mi单位的钱,并有pi的概率被抓到.在各个银行被抓到是独立事件.总的被抓到的概率不能超过P. ...
- Java缓冲流高效大文件的复制实例
public class BufferedDemo { public static void main(String[] args) throws FileNotFoundException { // ...
- http各个状态码的含义
http各个状态码的含义:由三位数字组成,第一位定义了状态码的类型 常见状态码及解决方法 404:找不到,地址错误 500:逻辑错误 400:一般是入参不匹配 504:超时 2开头:(请求成功)表示成 ...
- [JSOI2004]平衡点 / 吊打XXX 题解
预备概念: 金属退火:将金属缓慢加热到一定温度,保持足够时间,然后以适宜速度冷却 温度:一个逐渐减小的参数,表示接受次优解的概率 模拟退火是一种解决复杂问题的算法,相当于贪心,但以一个逐渐减小的该率接 ...
- PerPoly Collision(用物体本身模型做碰撞)
打开static mesh editor,在static mesh settings里找到collision complexity选项,选择最后一项: Use Complex collision as ...