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 ...
随机推荐
- left join on and和left join on where条件的困惑[转]
外连接:left join(左联接) left outer join 返回包括左表中的所有记录和右表中联结字段相等的记录right join(右联接) right outer join返回包括右表中的 ...
- LA 3263 That Nice Euler Circuit(欧拉定理)
That Nice Euler Circuit Little Joey invented a scrabble machine that he called Euler, after the grea ...
- 线程中sleep和wait方法的区别
sleep() 方法: 线程主动放弃CPU,使得线程在指定的时间内进入阻塞状态,不能得到CPU 时间,指定的时间一过,线程重新进入可执行状态.典型地,sleep()被用在等待某个资源就绪的情形:测试发 ...
- 雷哥带你了解webSocket原理
偶然在知乎上看到一篇回帖,瞬间觉得之前看的那么多资料都不及这一篇回帖让我对 websocket 的认识深刻有木有.所以转到我博客里,分享一下.比较喜欢看这种博客,读起来很轻松,不枯燥,没有布道师的阵仗 ...
- frugally-deep: Header-only library for using Keras models in C++
// Convenience wrapper around predict for models with // single tensor outputs of shape (1, 1, 1), / ...
- 利用xcode Build生成模拟器运行包
真机只能运行.ipa包 模拟器上只能运行.app包 xcode中生成.app包步骤: 启动xcode IDE,打开gigold源码工程 [project]——[gigold]——[Basic]:修改V ...
- springboot2整合logback.xml动态修改日志打印级别
今天找bug烦到了,生产上的日志级别不能修改,非常不利于排查问题,于是想到了动态修改日志打印级别, 因为上一周把项目升级成springboot2,并且使用logback.xml管理日志打印,所以修改也 ...
- Flink 实战:如何解决生产环境中的技术难题?
大数据作为未来技术的基石已成为国家基础性战略资源,挖掘数据无穷潜力,将算力推至极致是整个社会面临的挑战与难题. Apache Flink 作为业界公认为最好的流计算引擎,不仅仅局限于做流处理,而是一套 ...
- 路由Vue-router 的使用总结
1.关于 router-view 匹配 vue 项目使用 vue-router,所有的根级别的路由都是在 App.vue 文件中的 router-view 中渲染的.比如下面的 path: '/' . ...
- C#中如何通过点击按钮切换窗口
实现方法如下: 1.设计 首先在左侧放一个panel,右侧放一个panel(命名为pnlMain),调整大小,在左侧panel里放置两个按钮(多个按钮同理) 2.在按钮里面写方法 在[命名规范检查] ...