Description
Your task in this problem is to determine the number of divisors of
Cnk. Just for fun -- or do you need any special reason for such a useful computation?
Input
The input consists of several instances. Each instance consists of a single line containing two integers n and k (0 ≤ k ≤ n ≤ 431), separated by a single space.
Output
For each instance, output a line containing exactly one integer -- the number of distinct divisors of
Cnk. For the input instances, this number does not exceed 2
63 - 1.
Sample Input
5 1 6 3 10 4
Sample Output
2 6 16
分析:一个数的因子个数求法 将数写成 n=p1^a*p2^b..pn^c; 也就是质因素乘积的形式 那么因子的个数就是 sum=(a+1)*(b+1)*...*(c+1);
code:
View Code
#include<stdio.h>
#include<string.h>
int p[90];
int v[432];
int pn;
int e[432][90];
void pri()
{
int i,j;
pn=0;
memset(v,0,sizeof(v));
for(i=2;i<=431;i++)
{
if(v[i]==0)
{
p[pn++]=i;
for(j=i;j<=431;j+=i)
v[j]=1;
}
}
}
void fac()
{
int i,j,k;
for(i=2;i<=431;i++)
{
k=i;
for(j=0;j<pn;j++)
while(k>1&&k%p[j]==0)
{ e[i][j]++; k/=p[j];}
}
for(i=3;i<=431;i++)
for(j=0;j<pn;j++)
e[i][j]+=e[i-1][j];
}
int main()
{
int i,n,k;
long long sum;
pri();
fac();
while(scanf("%d%d",&n,&k)!=EOF)
{
sum=1;
for(i=0;i<pn;i++)
sum*=(1+e[n][i]-e[n-k][i]-e[k][i]);
printf("%lld\n",sum);
}
return 0;
}