Last active
August 29, 2015 13:56
-
-
Save KT-Yeh/8878455 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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