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以内,有 ...
随机推荐
- angular-2-tutorial-2017
# angular-2-tutorial-2017https://www.sitepoint.com/understanding-component-architecture-angular/http ...
- 微信小程序-云开发实战教程
微信小程序-云开发实战教程 云函数,云存储,云数据库,云调用 https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/gettin ...
- window.ShadyCSS
window.ShadyCSS Web Components # install $ yarn add @webcomponents/shadycss@1.7.1 # OR $ npm i @webc ...
- CSS3 & Grid Layout All In One
CSS3 & Grid Layout All In One W3C https://www.w3.org/TR/css-grid-1/ Grid Layout is a new layout ...
- vscode & ignore .idea
vscode & ignore .idea settings.json .vscode & ignore .idea // 将设置放入此文件中以覆盖默认设置 { "files ...
- auto skip function args
auto skip function args https://repl.it/@xgqfrms/auto-skip-function-args "use strict"; /** ...
- EventEmitter & custom events & sub/pub
EventEmitter & custom events & sub/pub https://repl.it/@xgqfrms/PPLabs-frontend-answers // 5 ...
- flutter 长按图片保存到手机
main.dart import 'dart:io'; import 'package:flutter/material.dart'; import 'package:http/http.dart' ...
- redis五种数据类型的应用
redis的五种数据类型和使用场景 string类型 string类型多用于缓存 set key value(value可以为json字符串) setnx多用于分布式锁(后面详细整理) 计数器 inc ...
- mybatisPlus中的模糊查询问题
不能查询中文 记得在数据库的配置中写明编码格式characterEncoding=utf-8