output
standard output
The number "zero" is called "love" (or "l'oeuf" to be precise, literally means "egg" in French), for example when denoting the zero score in a game of tennis.
Aki is fond of numbers, especially those with trailing zeros. For example, the number 92009200 has two trailing zeros. Aki thinks the more trailing zero digits a number has, the prettier it is.
However, Aki believes, that the number of trailing zeros of a number is not static, but depends on the base (radix) it is represented in. Thus, he considers a few scenarios with some numbers and bases. And now, since the numbers he used become quite bizarre, he asks you to help him to calculate the beauty of these numbers.
Given two integers nn and bb (in decimal notation), your task is to calculate the number of trailing zero digits in the bb-ary (in the base/radix of bb) representation of n!n! (factorial of nn).
质数分解定理的应用。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#define mem(a,x) memset(a,x,sizeof(a))
#define s1(x) scanf("%d",&x)
#define s2(x,y) scanf("%d%d",&x,&y)
#define s3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define s4(x,y,z,k) scanf("%d%d%d%d",&x,&y,&z,&k)
#define ls 2*rt
#define rs 2*rt+1
#define lson ls,L,mid
#define rson rs,mid+1,R
#define ll long long
using namespace std;
typedef pair<int,int> pii;
//inline ll ask(int x){ll res=0;while(x)res+=c[x],x-=x&(-x);return res;}
//inline void add(int x,int d){while(x<=n)c[x]+=d,x+=x&(-x);}
//int gcd(int a, int b) { return b == 0 ? a : gcd(b, a%b);}
const ll inf = 0x3f3f3f3f;
const int mx = 1e5+10;
ll n,b;
int main(){
//freopen("C:\\Users\\black\\Desktop\\in.txt","r",stdin);
//int T=10; scanf("%d",&T);
scanf("%lld%lld",&n,&b);
// ll sq = sqrt(b);
ll ans = 1e18;
for(ll i= 2; i <= b; i++){
if(i*i > b) i = b; // no equal
ll x = 0;
while(b%i==0){
b /= i;
x++;
}
if(x== 0) continue;
ll te = n,co=0;
while(te/i >= 1){
co += te / i;
te /= i;
}
/* long long tmp = 0, mul = 1;
while (mul <= n / i) {mul *= i; tmp += n / mul;}*/
// cout<<"tmp="<<tmp<<"X="<<x<<endl;
// cout<<"i="<<i<<"tmp="<<tmp<<endl;
ans = min(ans,co/x);
}
cout<<ans;
return 0;
}
本文已参与「新人创作礼」活动,一起开启掘金创作之路