题面

传送门

分析

我们先考虑n!在10进制下有多少个0

由于10=2*5,

我们考虑n!的分解式中5的指数,答案显然等于\(\frac{n}{5}+\frac{n}{5^2}+\frac{n}{5^3}+\dots\frac{n}{5^k}(\frac{n}{5^k}\geq 1,\frac{n}{5^{k+1}}<1)\)

可以用一个递归函数来计算:

ll f(ll x,ll y){
if(x<y) return 0;
else return x/y+f(x/y,y);
}

由于5的个数显然比2少,0的个数取决于5的个数

对于b进制下的0的个数

我们先把b质因数分解\(b=\prod p^{k_{i}}_{i}\)

对于每个质因数\(p_i\),我们按照递归函数求出n!中\(p_i\)的指数,然后再除以\(k_i\)

由于有指数影响,最大的质因数不一定出现的个数最小,不能像10进制那样直接计算

所以我们把每个质因数的结果取min即可

代码

#include<iostream>
#include<cstdio>
#include<cmath>
#define maxn 1000005
using namespace std;
typedef long long ll;
ll n,base;
ll p[maxn],k[maxn];
int cnt=0;
void divide(ll x){
ll sq=sqrt(x);
ll ans=0;
for(ll i=2;i*i<=x;i++){
if(x%i==0){
p[++cnt]=i;
while(x%i==0){
x/=i;
k[cnt]++;
}
}
}
if(x>1){
p[++cnt]=x;
k[cnt]=1;
}
}
ll f(ll x,ll y){
if(x<y) return 0;
else return x/y+f(x/y,y);
}
ll count(ll n,ll x){
divide(x);
ll ans=0x7fffffffffffffff;
for(int i=1;i<=cnt;i++){
ans=min(ans,f(n,p[i])/k[i]);
}
return ans;
}
int main(){
cin>>n>>base;
cout<<count(n,base);
}

Codeforces 1114C(数论)的更多相关文章

  1. Trailing Loves (or L'oeufs?) CodeForces - 1114C (数论)

    大意: 求n!在b进制下末尾0的个数 等价于求n!中有多少因子b, 素数分解一下, 再对求出所有素数的最小因子数就好了 ll n, b; vector<pli> A, res; void ...

  2. Codeforces - 1114C - Trailing Loves (or L'oeufs?) - 简单数论

    https://codeforces.com/contest/1114/problem/C 很有趣的一道数论,很明显是要求能组成多少个基数. 可以分解质因数,然后统计各个质因数的个数. 比如8以内,有 ...

  3. CodeForces 300C --数论

    A - A Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  4. CodeForces 359D (数论+二分+ST算法)

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=47319 题目大意:给定一个序列,要求确定一个子序列,①使得该子序 ...

  5. Codeforces 264B 数论+DP

    题目链接:http://codeforces.com/problemset/problem/264/B 代码: #include<cstdio> #include<iostream& ...

  6. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力

    题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...

  7. codeforces 1114C

    题目连接 : https://codeforces.com/contest/1114/problem/C 题目大意:给一个整数n(1e18>=n>=0),和一个整数k(1e12>=k ...

  8. CodeForces 1202F(数论,整除分块)

    题目 CodeForces 1213G 做法 假设有\(P\)个完整的循环块,假设此时答案为\(K\)(实际答案可能有多种),即每块完整块长度为\(K\),则\(P=\left \lfloor \fr ...

  9. Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)

    Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...

随机推荐

  1. presentingViewController、presentedViewController区别

    解释两个属性:presentingViewController 和 presentedViewController A----(present)-----B----(present)-----C 1. ...

  2. React(5) --绑定函数事件

    绑定函数事件 在以类继承的方式定义的组件中,为了能方便地调用当前组件的其他成员方法或属性(如:this.state),通常需要将事件处理函数运行时的 this 指向当前组件实例. run(){     ...

  3. 微信小程序(18)-- 自定义头部导航栏

    最近做的项目涉及相应的页面显示相应的顶部标题,所以就需要自定义头部导航了. 首先新建一个顶部导航公用组件topnav,导航高度怎么计算? 1.wx.getSystemInfo 和 wx.getSyst ...

  4. Mystery——团队作业——系统设计

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1 这个作业要求在哪里 https://edu.cnblo ...

  5. Sass--传多个参数

    Sass 混合宏除了能传一个参数之外,还可以传多个参数,如: @mixin center($width, $height) { width: $width; height: $height; posi ...

  6. Spring-quartz定时系统多任务配置

    <!-- 启动触发器的配置开始 --> <bean name="startQuertz" lazy-init="false" autowire ...

  7. netty-Selector

    上图中加入一句: socketChannel.configureBlocking(false);//设置为非阻塞的 keyIterator.clear(); 每连接一个SocketChannel 都会 ...

  8. Codeforces 842C--Ilya And The Tree(dfs+树)

    原题链接:http://codeforces.com/contest/842/problem/C 题意:一个以1为根节点的树,每个节点有一个值ai,定义美丽度:从根节点到这个节点的路径上所有ai的gc ...

  9. truncate与delete删除数据的区别

  10. asd的甩锅计划

    asd的甩锅计划 时间限制: 1 Sec  内存限制: 128 MB提交: 177  解决: 19[提交][状态] 题目描述 大家对hdu上面的畅通工程系列一定很熟悉了吧.比如如下一段,就是畅通工程里 ...