题目链接:http://codeforces.com/contest/1114/problem/C

题目大意:给你n和b,让你求n的阶乘,转换成b进制之后,有多少个后置零。

具体思路:首先看n和b,都比较大,肯定不能暴力做的,然后我们就想能不能通过分解质因数的方法来进行,当阶乘的值有多少b时,就会有多少满足情况的0。

当b是10的时候,可以分解成5*2,那么我们就求哪一个中,在n!中的个数最少,计算公式:

n的阶乘中素因子p的个数:

f(n)=⌊n/p⌋+⌊n/(p^2)⌋+⌊n/(p^3)⌋+⋯

当n为4,n的阶乘是24,b为4,24的二进制表示方法是16+8,最终算出来的后置0的个数是3,按照上面的公式,因子是2,f(4)=3,因为4是2的平方,所以还需要除以2,,按照进制就很好理解了。

PS:这个题在寻找最小值的时候,一定要注意初始值大一点啊,我一开始赋值1e18还不够,9e18才差不多的。。。

AC代码:

 #include<iostream>
#include<stack>
#include<stdio.h>
#include<map>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
# define lson l,m,rt<<
# define rson m+,r,rt<<|
# define ll long long
const int maxn = 1e5+;
ll sto1[maxn],sto2[maxn];
ll sto3[maxn];
ll cal(ll t1,ll t2)
{
ll tmp=;
while(t2)
{
tmp+=(t2/t1);
t2/=t1;
}
return tmp;
}
int main()
{
ll n,m,tmp;
scanf("%lld %lld",&n,&m);
tmp=m;
int num=;
for(ll i=; i*i<=m; i++)
{
int res=;
if(tmp%i==)
{
sto1[++num]=i;
while(tmp%i==)
{
tmp/=i;
res++;
}
sto2[num]=res;
}
}
if(tmp!=)sto1[++num]=tmp,sto2[num]=;
for(int i=; i<=num; i++)
{
sto3[i]=cal(sto1[i],n);
// cout<<sto1[i]<<" "<<sto2[i]<<" "<<sto3[i]<<endl;
}
ll minn=9e18+;
for(int i=; i<=num; i++)
{
minn=min(minn,sto3[i]/sto2[i]);
}
printf("%lld\n",minn);
return ;
}

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

  1. CF 1114 C. Trailing Loves (or L'oeufs?)

    C. Trailing Loves (or L'oeufs?) 链接 题意: 问n!化成b进制后,末尾的0的个数. 分析: 考虑十进制的时候怎么求的,类比一下. 十进制转化b进制的过程中是不断mod ...

  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. Trailing Loves (or L'oeufs?)

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

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

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

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

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

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

  8. 【Codeforces 1114C】Trailing Loves (or L'oeufs?)

    [链接] 我是链接,点我呀:) [题意] 问你n!的b进制下末尾的0的个数 [题解] 证明:https://blog.csdn.net/qq_40679299/article/details/8116 ...

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

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

随机推荐

  1. 学习笔记之csrf

    CBV 添加 csrf 第一种: 指定方法方面添加 装饰器 @memethod_decorator(xxx) 第二种 全部添加: 注意 在类名前: @method_decorator(xxx,name ...

  2. obj.attr = 5 == obj._dict_["attr"] = 5,调用super相当于调用父类方法进行重新构造

  3. P2209 [USACO13OPEN]燃油经济性Fuel Economy

    题面 sol:(思想):开一个大根堆和一个小根堆,每次计算到下了一个加油站用掉的油时尽量用小根堆中的元素,且同时删去大根堆中的相应位置的元素,当前加油站如果足够便宜,就可以把大根堆中的元素替换掉: ( ...

  4. ubuntu16.04 NFS系统挂载

    一:服务器端 step1:关闭防火墙 sudo ufw disable step2:安装nfs sudo apt-get install nfs-kernel-server step3: 打开/etc ...

  5. 自学Zabbix9.1 Network Discovery 网络发现原理

    点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix9.1 Network Discovery 网络发现原理 1. 网络发现简介 网络 ...

  6. django xadmin

    1.11.13版本下的[安装]: 1.下载分支版本 https://github.com/nocmt/Xadmin1.11.x/archive/master.zip 2.解压,并将其放在site-pa ...

  7. Impacket官方使用指南

      什么是Impacket Impacket是用于处理网络协议的Python类的集合.Impacket专注于提供对数据包的简单编程访问,以及协议实现本身的某些协议(例如SMB1-3和MSRPC).数据 ...

  8. CDQZ多校集训记

    20171218 DAY0 初相逢 今天的阳光很好,确实好极了.下午开始时,mercer说门外站了一堆人,我看都不用看就知道是衡水的.衡水人,怎么说呢,觉得还是挺不一样的.不知道像凡哥和超哥这种奇异的 ...

  9. A1001. A+B Format

    Calculate a + b and output the sum in standard format -- that is, the digits must be separated into ...

  10. 设置 webstorm 对 .vue 高亮

    1. 首先安装vue插件,安装方法: setting  -->  plugin  ,点击plugin,在内容部分的左侧输入框输入vue,会出现两个关于vue的插件,点击安装即可.安装完成后,就可 ...