Codeforces1114C. Trailing Loves (or L'oeufs?)-(质因子分解)
题目大意:
求n!转化为b进制后后导0的个数
思路:
我们首先考虑十进制转化为二进制者后,后导0的个数如何求
十进制数num
y = num%2
num/=2
如果y为0则,该位为0,就是求num能连续除以几次2(在整除的条件下)
十进制是num,进制为b
我们可以采取同样的思路
但是!
这里n!太大了,没法直接算出来
我们采取分解质因子的方式
同时我们对b也分解质因子(因为num要包含整个的b,如果b分解质因子之后的每一项都包含,则说明有整除关系)
n! --> a1[i]^b1[i] * a2[i]^b2[i] * a3[i]*b3[i]
b --> c1[i]^d1[i] * c2[i]^d2[i] * c3[i]*d3[i]
对b的每项在N!中查找包含了几个,取min就是答案
注意爆long long
Code:

ll n, b, ans = 1e18;
ll cal(ll t, ll temp)
{
ll res = 0;
ll nn = n;
for(ll i = t; i <= n ; i *= t)
{
res += (n / i);
if(i*t >n) break;
}
return res / temp;
}
void solve(ll num)
{
for(ll i = 1 ; i <= x ; i++)
{
ll t = p[i];
if(t > num) break;
ll temp = 0;
while(num % t == 0)
{
num /= t;
temp++;
}
if(temp) ans = min(ans, cal(t, temp));
}
if(num > 1) ans = min(ans, cal(num, 1));
}
int main()
{
oula();
n = read(), b = read();
solve(b);
out(ans);
return 0;
}
Codeforces1114C. Trailing Loves (or L'oeufs?)-(质因子分解)的更多相关文章
- Codeforces1114C Trailing Loves (or L'oeufs?)
链接:http://codeforces.com/problemset/problem/1114/C 题意:给定数字$n$和$b$,问$n!$在$b$进制下有多少后导零. 寒假好像写过这道题当时好像完 ...
- 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 ...
- C. Trailing Loves (or L'oeufs?)
题目链接:http://codeforces.com/contest/1114/problem/C 题目大意:给你n和b,让你求n的阶乘,转换成b进制之后,有多少个后置零. 具体思路:首先看n和b,都 ...
- 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以内,有 ...
随机推荐
- gitignore auto generator
gitignore auto generator .gitignore https://gitignore.io/ https://www.toptal.com/developers/gitignor ...
- Open Collective
Open Collective Open Collective is an online funding platform for open and transparent communities. ...
- Win/Mac 键位映射 & 在 Mac 上更改“键盘”偏好设置
Win/Mac 键位映射 & 在 Mac 上更改"键盘"偏好设置 PC键盘 在Mac下Command/Option键切换 https://support.apple.com ...
- CSS3 Animation & linear-gradient & css3 var & @keyframes
CSS3 Animation & linear-gradient & css3 var & @keyframes https://www.zhangxinxu.com/word ...
- GMV (Gross Merchandise Volume)
GMV (Gross Merchandise Volume) 商品总销量 https://www.zhihu.com/question/20146641 GMV=1销售额+2取消订单金额+3拒收订单金 ...
- Union international inc引进微信线下支付,开启消费无现金时代
长期以来,Union international inc娱乐集团(公司编号:20151533091)因其客户来自全球各国,特别是除了美国之外的中国用户居多,因此公司一直和中国领先的社交软件微信保持着良 ...
- DHCP (Dynamic Host Configuration Protocol )协议的探讨与分析
DHCP (Dynamic Host Configuration Protocol )协议的探讨与分析 问题背景 最近在工作中遇到了连接外网的交换机在IPv6地址条件下从运营商自动获取的DNS地址与本 ...
- C++算法代码——和为给定数
题目来自:http://218.5.5.242:9018/JudgeOnline/problem.php?cid=1376&pid=0 题目描述 给出若干个整数,询问其中是否有一对数的和等于给 ...
- 死磕以太坊源码分析之EVM如何调用ABI编码的外部方法
死磕以太坊源码分析之EVM如何调用ABI编码的外部方法 配合以下代码进行阅读:https://github.com/blockchainGuide/ 写文不易,给个小关注,有什么问题可以指出,便于大家 ...
- VMware 安装 CentOS7 后的简单配置
1.连网 如果能连网,跳过此步 试着ping一下百度 ping baidu.com 动态分配 IP sudo vim /etc/sysconfig/network-scripts/ifcfg-ens3 ...