#include<iostream> #include<cmath> using namespace std; int primef[1001];//质因子个数 int primea[1001]; int main() { freopen("input.in", "r", stdin); freopen("output.out","w", stdout); int n, a; while (cin >> n>>a) { int i,j; //清空 for (i=0; i<1001; i++) { primef[i]=0; primea[i]=0; } int max;//循环条件 //对n!分解质因子 for(i=n; i>=0; i--) { bool isOver = false; int temp = i; while(!isOver) { max = sqrt((double)temp); for (j=2; j<=max; j++) { if (temp%j == 0) { primef[j]++; temp /= j; break; } } if (j>max) { isOver = true; if(temp>1) { primef[temp]++; } } } } //对a分解质因子 int tmp = a; bool isOver = false; while(!isOver) { max = sqrt((double)tmp); for (j=2; j<=max; j++) { if (tmp%j == 0) { primea[j]++; tmp /= j; break; } } if (j>max) { if(tmp>1) { primea[tmp]++; } isOver = true; } } //寻找最小次数 int minIndex = 1000; for (i=2; i<=a; i++) { if (primea[i]!=0 &&primef[i]/primea[i] <minIndex) { minIndex = primef[i]/primea[i]; } } cout << minIndex << endl; } return 0; }