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$进制下有多少后导零. 寒假好像写过这道题当时好像完 ...
随机推荐
- Codeforces 1103 E. Radix sum
题目链接 神题. 题意:给定一个长度为\(10^5\)的幂级数\(a\),将卷积的下标运算定义为十进制下的不进位加法,求\(a^k\)模\(2^{58}\)的结果.\(k\leq 10^9\). 题解 ...
- day27 多态 多继承 接口类 抽象类
简单来说:多态就是指一个相同的方法名在不同的对象调用的时候实现一样或者不一样的方法实例1: 动物类有个方法 "嚎叫" 狗类也有个方法 "嚎叫" 猫类继承了动物类 ...
- MT【30】椭圆的第二定义解题
问题:上式表示的区域是怎样的? 解答:利用椭圆第二定义易知当取等号时为椭圆,又令$y$趋向于$+\infty$时不等号不成立,故可以判断为椭圆内部区域. 评:利用mathmatics软件容易得到
- 自学Linux Shell11.5-执行数字运算
点击返回 自学Linux命令行与Shell脚本之路 11.5-执行数字运算 1. Shell基本运算符 Shell 和其他编程语言一样,支持多种运算符,包括: 算数运算符 关系运算符 布尔运算符 字符 ...
- Codeforces 1106F Lunar New Year and a Recursive Sequence | BSGS/exgcd/矩阵乘法
我诈尸啦! 高三退役选手好不容易抛弃天利和金考卷打场CF,结果打得和shi一样--还因为queue太长而unrated了!一个学期不敲代码实在是忘干净了-- 没分该没分,考题还是要订正的 =v= 欢迎 ...
- HGOI 20190217 题解
/* for me,开训第一天 /beacuse 文化课太差被抓去补文化课了... 看一眼题 : AK局? 但是,Wa on test #10 in problem C 290! (就差那么一咪咪) ...
- 安装 scrapy 报错 error: Microsoft Visual C++ 14.0 is required
问题描述 使用 pip install scrapy 安装 scrapy 时出现以下错误: error: Microsoft Visual C++ 14.0 is required 错误提示中给出了一 ...
- 基本数据类型对象包装(Integer等)
基本数据类型 包装类 byte Byte short Short int Integer long Long boolean Boolean float ...
- mfc editline 变为大框框
属性:
- MQ与webservice的区别,MQ的区别
Webservice 和MQ(MessageQueue)都是解决跨平台通信的常用手段,两者有哪些区别呢? 个人认为最本质的区别在于 Webservice近乎实时通信,而MQ却通常是延时通信. 什么意思 ...