CF 1114 C. Trailing Loves (or L'oeufs?)
C. Trailing Loves (or L'oeufs?)
题意:
问n!化成b进制后,末尾的0的个数。
分析:
考虑十进制的时候怎么求的,类比一下。
十进制转化b进制的过程中是不断mod b,/ b,所以末尾的0就是可以mod b等于0,那么就是这个数中多少个b的幂。
所以考虑哪些数和乘起来构成b,对b质因数分解后,这些质因数可以构成一个b。
对于n个阶乘,可以直接求出每个质因数中幂是多少。然后取下min。
代码:
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cmath>
#include<cctype>
#include<set>
#include<queue>
#include<vector>
#include<map>
using namespace std;
typedef long long LL; inline int read() {
int x=,f=;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-;
for(;isdigit(ch);ch=getchar())x=x*+ch-'';return x*f;
} int cnt[];
vector<LL> p; int main() {
LL n, b, t;
cin >> n >> b; t = b;
for (LL i = ; 1ll * i * i <= t; ++i) {
if (t % i) continue;
p.push_back(i);
while (t % i == ) cnt[(int)p.size() - ] ++, t /= i;
if (t == ) break;
}
if (t != ) { p.push_back(t); cnt[(int)p.size() - ] ++; }
LL ans = 1e18;
for (int i = ; i < (int)p.size(); ++i) {
LL tmp = n, now = p[i], sum = ;
while (tmp) { sum += (tmp / now); tmp /= now; }
ans = min(ans, sum / cnt[i]);
}
cout << ans;
return ;
}
CF 1114 C. Trailing Loves (or L'oeufs?)的更多相关文章
- CF#538 C - Trailing Loves (or L'oeufs?) /// 分解质因数
题目大意: 求n!在b进制下末尾有多少个0 https://blog.csdn.net/qq_40679299/article/details/81167283 一个数在十进制下末尾0的个数取决于10 ...
- 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进行 ...
- C. Trailing Loves (or L'oeufs?)
题目链接:http://codeforces.com/contest/1114/problem/C 题目大意:给你n和b,让你求n的阶乘,转换成b进制之后,有多少个后置零. 具体思路:首先看n和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 ...
- Codeforces - 1114C - Trailing Loves (or L'oeufs?) - 简单数论
https://codeforces.com/contest/1114/problem/C 很有趣的一道数论,很明显是要求能组成多少个基数. 可以分解质因数,然后统计各个质因数的个数. 比如8以内,有 ...
- Codeforces1114C Trailing Loves (or L'oeufs?)
链接:http://codeforces.com/problemset/problem/1114/C 题意:给定数字$n$和$b$,问$n!$在$b$进制下有多少后导零. 寒假好像写过这道题当时好像完 ...
- Trailing Loves (or L'oeufs?) CodeForces - 1114C (数论)
大意: 求n!在b进制下末尾0的个数 等价于求n!中有多少因子b, 素数分解一下, 再对求出所有素数的最小因子数就好了 ll n, b; vector<pli> A, res; void ...
随机推荐
- Oracle使用order by排序关于null值处理
select * from dual order by age desc nulls last select * from test order by age asc nulls first sqls ...
- RESET MASTER和RESET SLAVE使用场景和说明
[前言]在配置主从的时候经常会用到这两个语句,刚开始的时候还不清楚这两个语句的使用特性和使用场景. 经过测试整理了以下文档,希望能对大家有所帮助: [一]RESET MASTER参数 功能说明:删除所 ...
- 使用UICollectionView
使用UICollectionView 使用UICollectionView的流程: 1. 设定一个UICollectionViewFlowLayout 2. 使用这个设定的UICollectionVi ...
- Difference Between Arraylist And Vector : Core Java Interview Collection Question
Difference between Vector and Arraylist is the most common Core Java Interview question you will co ...
- 触发器 视图 存储过程 mysql常用函数
...
- saltstack-把执行结果存储到mysql服务内
saltstack把执行的结果保存到mysql中,以便进行命令安全审计 mysql负责存储数据,mysql-python负责收集数据 master需要安装mysql和MySQL-python,mini ...
- 11g数据库查看dataguard是否同步
一.环境 主库: ip地址:192.168.122.203 oracle根目录:/data/db/oracle SID:qyq 数据文件路径/ ...
- php 实现hash表
hash表又称散列表,通过把关键字key经过hash函数映射到hash表中某个位置获取记录. 存放记录的数组又称为hash表,映射函数称为hash函数 下面是php中实现hash表的方法 <?p ...
- 【译文】Web Service 众所周知的问题
1. 什么是web service Web Service是一种网络程序间的通信方式,它允许开发者用API方式暴露自己的业务逻辑功能,这样,其他开发者可以使用它 2. Web Service的特性 互 ...
- iptables.md
iptables基本概念 工作流程 1.一个数据包进入网卡时,它首先进入PREROUTING链,内核根据数据包目的IP判断是否需要转发出去. 2.如果数据包就是进入本机的,它就会沿着图向下移动,到达I ...