C. Trailing Loves (or L'oeufs?) (质因数分解)
C. Trailing Loves (or L'oeufs?)
题意:
求n!在b进制下末尾有多少个0?
思路:
类比与5!在10进制下末尾0的个数是看2和5的个数,那么
原题就是看b进行质因数分解后,每个因数个数的最小值
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 1000005
ll pri[N];
ll cnt[N];
ll tot;
void getpri(ll x)
{
memset(cnt,,sizeof(cnt));
memset(pri,,sizeof(pri));
for(ll i=;i*i<=x;i++)
{
while(x%i==)
{
pri[tot]=i;
cnt[tot]++;
x/=i;
}
if(cnt[tot]) tot++;
}
if(x>) pri[tot]=x,cnt[tot++]++;
}
ll solve(ll x,ll p)
{
ll res=;
while(x)
{
res+=x/p;
x/=p;
}
return res;
}
int main()
{
ll n,b;
while(~scanf("%lld %lld",&n,&b)){
tot=;
getpri(b);
ll maxn=1e18;
/*for(int i=0;i<tot;i++)
cout<<pri[i]<<" "<<cnt[i]<<endl;*/
for(ll i=;i<tot;i++)
{
maxn=min(maxn,solve(n,pri[i])/cnt[i]);
}
printf("%lld\n",maxn);
} 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 ...
- 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 ...
- CF#538 C - Trailing Loves (or L'oeufs?) /// 分解质因数
题目大意: 求n!在b进制下末尾有多少个0 https://blog.csdn.net/qq_40679299/article/details/81167283 一个数在十进制下末尾0的个数取决于10 ...
- 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?)
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 ...
随机推荐
- 树——populating-next-right-pointers-in-each-node(填充每个节点的next指针)
问题: Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode ...
- Spring的AOP和IoC及隔离级别
Spring的AOP和IoC Spring AOP:代理机制.Spring提供的自动代理机制 Spring的IoC来实组件之间的依赖关系注入, 使控制层与业务实现分离,即客户通过调用业务委托接口来调用 ...
- loadrunner 使用
loadrunner给我的感觉很强势吧,第一次接触被安装包吓到了,当时用的是win10安装11版本的,各种安装失败,印象很深刻,那时候全班二三十号人,搞环境搞了两天,后来无奈,重做系统换成win7的了 ...
- 对vueloader的研究
vue-loader是webpack的加载器,允许您以称为单文件组件(SFC)的格式创作Vue组件: <template> <div class="example" ...
- Vue项目【饿了么App】mock数据【data.json】
1.前后端分离式开发,约定好数据字段接口! 2.前端mock静态数据,开发完毕后,与后端进行数据联调! 3.vue.config.js 配置 devServer const appData = req ...
- NIO之Buffer操作示例
1. buffer常规操作 略 2. 只读buffer /** * 只读buffer */ public class BufferTest01 { public static void main(St ...
- BZOJ 4836: [Lydsy1704月赛]二元运算 分治FFT
Code: #include<bits/stdc++.h> #define ll long long #define maxn 500000 #define setIO(s) freope ...
- 【Java】Java中charAt()方法的使用
说明 java.lang.String.charAt() 方法返回指定索引处的char值.索引范围是从0到length() - 1.对于数组索引,序列的第一个char值是在索引为0,索引1,依此类推 ...
- IHttpHandler
https://docs.microsoft.com/en-us/dotnet/api/system.web.ihttphandler?view=netframework-4.8 Defines th ...
- __I、 __O 、__IO是什么意思?怎么用?
出处:http://www.chuxue123.com/forum.php?mod=viewthread&tid=122&ctid=3 __I. __O .__IO是什么意思?这是ST ...