C. Trailing Loves (or L'oeufs?)
题目链接: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?)的更多相关文章
- 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 ...
- C. Trailing Loves (or L'oeufs?) (质因数分解)
C. Trailing Loves (or L'oeufs?) 题目传送门 题意: 求n!在b进制下末尾有多少个0? 思路: 类比与5!在10进制下末尾0的个数是看2和5的个数,那么 原题就是看b进行 ...
- Trailing Loves (or L'oeufs?)
The number "zero" is called "love" (or "l'oeuf" to be precise, literal ...
- 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?) CodeForces - 1114C (数论)
大意: 求n!在b进制下末尾0的个数 等价于求n!中有多少因子b, 素数分解一下, 再对求出所有素数的最小因子数就好了 ll n, b; vector<pli> A, res; void ...
- 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 ...
- Codeforces1114C Trailing Loves (or L'oeufs?)
链接:http://codeforces.com/problemset/problem/1114/C 题意:给定数字$n$和$b$,问$n!$在$b$进制下有多少后导零. 寒假好像写过这道题当时好像完 ...
随机推荐
- codeforces510B
Fox And Two Dots CodeForces - 510B Fox Ciel 正在玩一个手机拼图游戏,被称之为 "Two Dots".基础关卡是在一个大小为 n × m的 ...
- BZOJ3835[Poi2014]Supercomputer——斜率优化
题目描述 Byteasar has designed a supercomputer of novel architecture. It may comprise of many (identical ...
- MT【70】图论的一些基本概念例题介绍
此讲是纯粹竞赛,联赛二试题难度.仅供学有余力的学生看看.
- Rsync 客户端配置
安装rsync服务yum -y install rsync 创建密码文件rsync.passwordvi /etc/rsync.password只存储密码即可,无需用户名.密码为Rsync服务器端的/ ...
- 【题解】 bzoj1076: [SCOI2008]奖励关 (装压+期望dp)
题面戳我 Solution 并不会做,看了下题解大概了解了.期望这个东西好难搞啊qwq 我们定义\(dp[i][j]\)表示第\(i\)步,拿到宝物前的状态为\(j\). 正着来会有很多不合法的情况, ...
- DHCP的原理和实现过程
在DHCP过程中有两个对象DHCP客户端和DHCP服务端,而且DHCP在三层是通过可靠地TCP协议实现,DHCP服务运行在67和68端口. DHCP实现的简单过程,如图1所示, 图1 文字描述: 1. ...
- centos6.5重新调整/home和跟目录/大小
0. 说明 系统刚刚安装完之后,默认到/home有1.5TiB,而根分区只有200G.现在是要将VolGroup-lv_home缩小到200G,并将剩余的空间添加给VolGroup-lv_root. ...
- Centos6.5使用yum安装mysql
0. 说明 先要查看yum源是否有你想要的mysql版本 yum list | grep mysql 如果没有则先要更新yum源 yum -y update 更新后即可进行下一步操作. 1. yum安 ...
- [Nginx] – 性能优化 – 配置文件优化
Nginx基本安全优化 1.调整参数隐藏Nginx版本号信息 一般来说,软件的漏洞都和版本有关,因此我们应尽量隐藏或清除Web服务队访问的用户显示各类敏感信息(例如:Web软件名称及版本号等信 ...
- 导入gradle项目
1.1 代码下载 将代码下载到本机具体位置: 根据svn地址用外部svn工具导入项目到本地一个目录 比如 d:/a 1.2 导入工程 1.2.1 导入gradle工具 1.2.2 选择代码路径 1.2 ...