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. 转:c# 安装包制作

    .net Windows服务程序和安装程序制作 最近项目中用到window服务程序,以前没接触过,比较陌生,花了两天的时间学习了下,写了个简单的服务,但在制作安装程序的时候,参照网上很多资料,却都制作 ...

  2. [翻译] ValueTrackingSlider

    ValueTrackingSlider What is it? A UISlider Subclass that displays live values in a popUpView. It’s i ...

  3. DPM恢复点和保持期、常见问题排除指南

    “恢复点计划”确定应为该保护组创建多少个恢复点. 对于文件保护,选择希望创建恢复点的日期和时间. 对于支持增量备份的应用程序数据保护,同步频率决定了恢复点计划. 对于不支持增量备份的应用程序数据保护, ...

  4. MFC连接postgre数据库

    配置环境: include:libpq-fe.h文件 lib:libpq.lib文件 dll:libeay32.dll,libiconv-2.dll,libintl-8.dll,libpq.dll,s ...

  5. Linux 文件特殊权限详解[suid/sgid/t]

    setuid(suid): 针对命令和二进制程序的,当普通用户执行某个(passwd)命令的时候,可以拥有这个命令对应用户的权限, 即让普通用户可以以root用户的角色执行程序或命令. setgid( ...

  6. Exchange & Office 365最小混合部署

    前言 这篇文章的主题是混合部署~ 混合使得本地组织和云环境像一个单一的.协作紧密的组织一样运作.当组织决定进行混合部署,达到本地Exchange Server和Office 365共存的状态时,就会面 ...

  7. DXperience 工具箱不显示/ Visual Studio 2012选择项打开崩溃

    1.移除NetFx40_LegacySecurityPolicy  节: 移除C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\I ...

  8. echarts中datazoom相关配置

    dataZoom=[ //区域缩放 { id: 'dataZoomX', show:true, //是否显示 组件.如果设置为 false,不会显示,但是数据过滤的功能还存在. backgroundC ...

  9. 用asp连接Access数据库 制作简单登陆界面

    [题外话:最近做Internet作业,在这写一个适合初学入门的ASP连接ACCESS数据库做登陆界面的简单的例子,以慰藉我一口气把以前做过的系统中的PHP代码全改成ASP代码来临时应付作业的心情... ...

  10. [CEOI2017]Building Bridges

    题目 斜率优化思博题,不想写了 之后就一直\(95\)了,于是靠肮脏的打表 就是更新了一下凸壳上二分斜率的写法,非常清爽好写 就当是挂个板子了 #include<algorithm> #i ...