#include <cstdio> #include <cmath> using namespace std; int find(int n, int b) { int max = -1;//寻找最大质因数 int flag1 = 1;//最大质因数数量 for (int i = 2; i <= b; i++) { while (b % i == 0) { b = b / i; if (max < i) { max = i; flag1 = 1; } else if (max == i) flag1++; } } int flag2 = 0;//能分解出来的最大质因数的数量 int temp; for (int i = 1; i <= n; i++) { temp = i; while (temp % max == 0) { temp /= max; flag2++; } } flag2 = flag2 / flag1; return flag2; } int main() { int n; int b, flag, len; double l; while (scanf("%d%d", &n, &b) != EOF) { flag = l = 0; for (int i = 1; i <= n; i++) l += log(i); len = l / log(b) + 1e-6; flag = find(n, b); printf("%d %d\n", flag, len + 1); } return 0; }
原文地址:http://blog.csdn.net/hyczms/article/details/37935603