CF#538 C - Trailing Loves (or L'oeufs?) /// 分解质因数
题目大意:
求n!在b进制下末尾有多少个0
https://blog.csdn.net/qq_40679299/article/details/81167283
一个数在十进制下末尾0的个数取决于10的幂的个数 即 1500=15*10^2 与两个0
在任意进制下也是 即n!在b进制下 n!=a*b^x 那么末尾0的个数就是 x
若b能分解出质因数 b1 b2 b3 ...
那么 a*b^x = a*(b1^x1 * b2^x2 * b3^x3 ... )^x = a*(b1^(x1*x) * b2^(x2*x) * b3^(x3*x) ... )
(x1表示能在b中分解出x1个b1...)
又可化成 A1*(b1^(x1*x)) 或A2*(b2^(x2*x))或 A3*(b3^(x3*x))的形式 即 A*B^X
对于特定的B 通过getcnt()可以求X 对于b1可求得X1 那么x=X1/x1
A的可能值有很多如A1 A2 A2 使得 n!=A*B^X解得的X也有多种
要使它们最终都满足 那么x应该是 X1/x1 X2/x2 X3/x3 ... 中最小的一个
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define mem(i,j) memset(i,j,sizeof(i))
const int mod=1e9+;
const LL maxn=1e18+;
const LL maxm=1e12+;
LL n, b;
LL pri[], ind=;
LL cnt[];
void get_pri(LL n) {
mem(pri,); mem(cnt,);
for(LL i=;i*i<=n;i++) {
while(n%i==)
pri[ind]=i, cnt[ind]++, n=n/i;
if(cnt[ind]) ind++;
}
if(n>) pri[ind]=n, cnt[ind++]=;
} // 分解质因数
LL getcnt(LL p,LL n){
LL res=;
while(n) res+=n/p, n/=p;
return res;
} // n!能分解出res个p
int main()
{
while(~scanf("%I64d%I64d",&n,&b)) {
ind=; get_pri(b); //printf("%d\n",ind);
LL ans=maxn;
for(LL i=;i<ind;i++)
ans=min(ans,getcnt(pri[i],n)/cnt[i]);
printf("%I64d\n",ans);
} return ;
}
CF#538 C - Trailing Loves (or L'oeufs?) /// 分解质因数的更多相关文章
- 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 ...
- CF 1114 C. Trailing Loves (or L'oeufs?)
C. Trailing Loves (or L'oeufs?) 链接 题意: 问n!化成b进制后,末尾的0的个数. 分析: 考虑十进制的时候怎么求的,类比一下. 十进制转化b进制的过程中是不断mod ...
- C. Trailing Loves (or L'oeufs?) (质因数分解)
C. Trailing Loves (or L'oeufs?) 题目传送门 题意: 求n!在b进制下末尾有多少个0? 思路: 类比与5!在10进制下末尾0的个数是看2和5的个数,那么 原题就是看b进行 ...
- 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 ...
- 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,都 ...
- 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 ...
随机推荐
- crypto 密码加密
转自 'use strict'; var crypto = require('crypto'); /** * generates random string of characters i.e sal ...
- Linux NIO 系列(04-2) poll
目录 一.select 和 poll 比较 二.poll API 附1:linux 每个进程IO限制 附2:poll 网络编程 Linux NIO 系列(04-2) poll Netty 系列目录(h ...
- 三、函数 (SUM、MIN、MAX、COUNT、AVG)
第八章 使用数据处理函数 8.1 函数 SQL支持利用函数来处理数据.函数一般是在数据上执行的,给数据的转换和处理提供了方便. 每一个DBMS都有特定的函数.只有少数几个函数被所有主要的DBMS等同的 ...
- 分布式ID生成器的解决方案总结
在互联网的业务系统中,涉及到各种各样的ID,如在支付系统中就会有支付ID.退款ID等.那一般生成ID都有哪些解决方案呢?特别是在复杂的分布式系统业务场景中,我们应该采用哪种适合自己的解决方案是十分重要 ...
- [轉]Reverse a singly linked list
Reverse a singly linked list http://angelonotes.blogspot.tw/2011/08/reverse-singly-linked-list.html ...
- 我的scoi2018
高一,很尴尬,凉~ -------- 大家好,我是分界线,我弱弱的说本次采用倒序的写作手法 -------- 故事是这样讲的: Day0: 刚刚去那个电科搞的集训,早上才考了一波模拟赛,下午就过来住酒 ...
- 一、hibernate环境搭建
hibernate环境搭建 下载hibernate hibernate的jar 连接数据库的jar 解压hibernate,解压后目录结构 documentation :对应hibernate开发文档 ...
- 关于solarwinds的一些介绍
由于是给客户使用,作为运维人员自然是要安装测试一下的. solarwinds是一个付费的监控软件,部署起来很方便,加agent节点也很方便,除了监控主机,还可以监控网络流量,交换机等设备.由于并没有实 ...
- matlab filtfilt 函数
紧接上一篇,简单分析matlab中的非常好用的 filtfilt 函数,一款零相移滤波函数. 其matlab中的语法如下: y = filtfilt(data,x);1非常简单,不是一般的简单!然而, ...
- PHP-在排序数组中查找元素的第一个和最后一个位置
给定一个按照升序排列的整数数组 nums,和一个目标值 target.找出给定目标值在数组中的开始位置和结束位置. 你的算法时间复杂度必须是 O(log n) 级别. 如果数组中不存在目标值,返回 [ ...