Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save KT-Yeh/8878455 to your computer and use it in GitHub Desktop.
Save KT-Yeh/8878455 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
int N,B;
while (scanf("%d%d",&N,&B) != EOF){
double digit = 0;
int factor[801] = {0};
double log10_B = log10(B);
// N!
for (int i = 2; i <= N; i++){
//計算位數
digit += (log10(i) / log10_B); // 換底公式log(B,i)
//計算i的質因數
for (int temp = i, j = 2; j <= B; j++){
while (temp % j == 0){
factor[j]++;
temp /= j;
}
}
}
// 計算有幾個0
int nOf0 = 0;
while (1){
int temp = B;
// 將因數從2~B跑過 看能不能使temp==1
for (int i = 2; i <= B; i++){
while (factor[i] && temp % i == 0){
factor[i]--;
temp /= i;
}
}
if (temp == 1) nOf0++;
else break;
}
printf("%d %d\n",nOf0,(int)digit+1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment