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. 远程桌面报错解决:No Remote Desktop License Servers Available

    摘 要 用户发来反馈,使用部门Windows跳板机报错:The remote session was disconnected because there are no Remote Desktop ...

  2. [UI] 精美UI界面欣赏[6]

    精美UI界面欣赏[6]

  3. Linux 系统的/usr目录

    /usr不是user的缩写,其实usr是Unix Software Resource的缩写, 也就是Unix操作系统软件资源所放置的目录,而不是用户的数据:所有系统默认的软件都会放置到/usr, 系统 ...

  4. ASP.NET Web Api vs Node.js Benchmark

    http://mikaelkoskinen.net/post/asp-net-web-api-vs-node-js-benchmark ASP.NET Web Api vs Node.js Bench ...

  5. Hello World ! 第一篇随笔

    Hello World ! 第一篇随笔 /* * Language: C++ * Code Name: Hello World ! * @author Metak */ #include <io ...

  6. Java基础知识强化107:DecimalFormat

    1. 引入: 如何控制输出数据的精度? >1. 使用Math.round方法 (1)Java如何把一个float(double)四舍五入到小数点后2位,4位,或者其它指定位数 ? 答:比如,如下 ...

  7. 安装VMware,Linux

    不是每一个程序员都必须玩过linux,只是博主觉得现在的很多服务器都是linux系统的,而自己属于那种前端也搞,后台也搞,对框架搭建也感兴趣,但是很多生产上的框架和工具都是安装在服务器上的,而且有不少 ...

  8. 【转】iOS:AvPlayer设置播放速度不生效的解决办法

    现象: 项目有一个需求是实现视频的慢速播放,使用的是封装的AvPlayer,但是设置时发现比如设置rate为0.5,0.1,0.01都是一样的速度,非常疑惑.后来经过查找资料,发现iOS10对这个AP ...

  9. 鴻雁 Anser cygnoides

    鴻雁 Anser cygnoides,其中 Anser 是屬名.雁屬的模式種是 Anser anser 灰雁,在中國也有分佈,但不如鴻雁和中國人關係密切.中國人所說的「大雁」一般指鴻雁,偶爾指灰雁或是 ...

  10. JAVA构造MAP并初始化MAP

    第一种方法:static块初始化 public class Demo{ private static final Map<String, String> myMap; static { m ...