C. Trailing Loves (or L’oeufs?)
题意
求
在b进制下末尾有多少个
做法
这道题我们首先考虑 进制,那就是看 能够整除 多少次和整除 多少次。取个 即是答案,这道题做法类似,我们只需要先对 进行分解质因数,对每个质因数统计在 中出现次数 和在 中出现次数 ,最后对所有的 取 即可
代码
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
ll solve(ll a,ll b)
{
if(a==0) return 0;
return a/b+solve(a/b,b);
}
int main()
{
ll a,b;
scanf("%lld%lld",&a,&b);
ll ans=LL_INF;
for(ll i=2;i*i<=b;i++)
{
if(b%i==0)
{
int cnt=0;
while(b%i==0)
{
cnt++;
b/=i;
}
ans=min(ans,solve(a,i)/cnt);
}
}
if(b>1) ans=min(ans,solve(a,b));
printf("%lld\n",ans);
return 0;
}