# 九度 oj 题目1104：整除问题

http://ac.jobdu.com/problem.php?pid=1104

			while(t){
cnt1[i] += t/primes[i];
t= t/primes[i];
}


k值为cnt1[i]/cnt2[i]的最大值。

#include <stdio.h>
#include <algorithm>

using namespace std;
int primes[1001];
bool temp[1001];

void init(){
for(int i =0; i<=1000;i++){
temp[i] = true;
}
for(int i =2; i<=1000;i++){
if(!temp[i]) continue;
for(int j = i*i ;j<=1000;j+=i){
temp[j] = false;
}
}
for(int i=2;i<=1000;i++){
if(temp[i]){
}
}
}

int main(int argc, char* argv[])
{
init();
int cnt1[1001],cnt2[1001];
int a,n;
int ans;
while(scanf("%d %d" ,&n,&a)!=EOF){
for(int i=0; i<=1000;i++){
cnt1[i] = cnt2[i] = 0;
}
ans = 0x7fffff;
int t = n;
while(t){
cnt1[i] += t/primes[i];
t= t/primes[i];
}

while(a%primes[i] ==0){
cnt2[i]++;
a=a/primes[i];
}
if(cnt2[i] == 0) continue;
if(cnt1[i]/cnt2[i] < ans){
ans = cnt1[i]/cnt2[i];
}
}
printf("%d\n",ans);
}
return 0;
}



#include <stdio.h>

int main(){
int n,a,k;
long long factor;
while(scanf("%d %d",&n,&a) !=EOF){
factor = 1;
k = 0;
for (int i = 1; i <=n; ++i) {
factor *= i;
while(factor%a==0){
k++;
factor /= a;
}
//factor = ma + x, ma will not help to increase k
//delete ma to prevent overflow
factor = factor % a;
}
printf("%d\n",k);
}
}