C. Trailing Loves (or L'oeufs?)

链接

题意:

  问n!化成b进制后,末尾的0的个数。

分析:

  考虑十进制的时候怎么求的,类比一下。

  十进制转化b进制的过程中是不断mod b,/ b,所以末尾的0就是可以mod b等于0,那么就是这个数中多少个b的幂。

  所以考虑哪些数和乘起来构成b,对b质因数分解后,这些质因数可以构成一个b。

  对于n个阶乘,可以直接求出每个质因数中幂是多少。然后取下min。

代码:

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} int cnt[];
vector<LL> p; int main() {
LL n, b, t;
cin >> n >> b; t = b;
for (LL i = ; 1ll * i * i <= t; ++i) {
if (t % i) continue;
p.push_back(i);
while (t % i == ) cnt[(int)p.size() - ] ++, t /= i;
if (t == ) break;
}
if (t != ) { p.push_back(t); cnt[(int)p.size() - ] ++; }
LL ans = 1e18;
for (int i = ; i < (int)p.size(); ++i) {
LL tmp = n, now = p[i], sum = ;
while (tmp) { sum += (tmp / now); tmp /= now; }
ans = min(ans, sum / cnt[i]);
}
cout << ans;
return ;
}

CF 1114 C. Trailing Loves (or L'oeufs?)的更多相关文章

  1. CF#538 C - Trailing Loves (or L'oeufs?) /// 分解质因数

    题目大意: 求n!在b进制下末尾有多少个0 https://blog.csdn.net/qq_40679299/article/details/81167283 一个数在十进制下末尾0的个数取决于10 ...

  2. 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 ...

  3. C. Trailing Loves (or L'oeufs?) (质因数分解)

    C. Trailing Loves (or L'oeufs?) 题目传送门 题意: 求n!在b进制下末尾有多少个0? 思路: 类比与5!在10进制下末尾0的个数是看2和5的个数,那么 原题就是看b进行 ...

  4. C. Trailing Loves (or L'oeufs?)

    题目链接:http://codeforces.com/contest/1114/problem/C 题目大意:给你n和b,让你求n的阶乘,转换成b进制之后,有多少个后置零. 具体思路:首先看n和b,都 ...

  5. Trailing Loves (or L'oeufs?)

    The number "zero" is called "love" (or "l'oeuf" to be precise, literal ...

  6. 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    ...

  7. Codeforces - 1114C - Trailing Loves (or L'oeufs?) - 简单数论

    https://codeforces.com/contest/1114/problem/C 很有趣的一道数论,很明显是要求能组成多少个基数. 可以分解质因数,然后统计各个质因数的个数. 比如8以内,有 ...

  8. Codeforces1114C Trailing Loves (or L'oeufs?)

    链接:http://codeforces.com/problemset/problem/1114/C 题意:给定数字$n$和$b$,问$n!$在$b$进制下有多少后导零. 寒假好像写过这道题当时好像完 ...

  9. Trailing Loves (or L'oeufs?) CodeForces - 1114C (数论)

    大意: 求n!在b进制下末尾0的个数 等价于求n!中有多少因子b, 素数分解一下, 再对求出所有素数的最小因子数就好了 ll n, b; vector<pli> A, res; void ...

随机推荐

  1. 使用vue做项目

    使用vue做项目需要用到node.js的npm来管理包 所以我们需要先下载node.js然后通过node的npm来管理包  安装完 nodejs后 我们需要执行 npm install vue-cli ...

  2. pycharm something

    e1:使用的版本2016.3 发现无法执行py程序,执行菜单为灰色.选择py为2.7. e2:使用过jython可以运行,但是语法有问题str.formate无法执行

  3. umount nfs文件系统 显示 umount.nfs: device is busy

    网上的方法一般都是 fuser -m  /nfs 查出进程号,然后杀死进程号,或者fuser -km /nfs直接杀死,我试了下都不行 解决方法: 对于nfs文件系统来说,umount -l /nfs ...

  4. python---九九乘法表代码

    #_*_ coding:utf-8 _*_# author choco ''' #while循环num1=0while num1<9: num1+=1 num2=1 while num2< ...

  5. React onPaste 获取粘贴板的值

    React 中, 获取 粘贴板的值, 使用下面的方法 console.log(e.clipboardData.getData('Text')); 如果是 JS 中的 onpaste 事件, 则使用 v ...

  6. ubuntu16.04安装visual-studio-code

    微软主页的安装说明,https://code.visualstudio.com/docs/setup/linux    有一点英语基础就能看懂,写的很好,一切以官方文档为主 方法一:可以使用umake ...

  7. Hadoop学习之路(五)Hadoop集群搭建模式和各模式问题

    分布式集群的通用问题 当前的HDFS和YARN都是一主多从的分布式架构,主从节点---管理者和工作者 问题:如果主节点或是管理者宕机了.会出现什么问题? 群龙无首,整个集群不可用.所以在一主多从的架构 ...

  8. openfalcon-0.2 配置

    hbs 配置文件 { "debug": true, "database": "openfalcon:123456@tcp(172.16.230.188 ...

  9. jQuery.fn.extend()

    jQuery.fn.extend() extend()方法是定义在jQuery构造函数的prototype对象上面的一个方法,这样做就能使得所有jQuery对象的实例都能共享这个方法.jQuery构造 ...

  10. oracle ORA-01722:无效数字 记录

    今天在对12万条记录的表进行左联接时,有时可以查询出数据,有时会报无效数字,反复检查,发现问题. 例如sql: SELECT * FROM USER U LEFT JOIN USER_ROLE UR ...