POJ 2992
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
先打表,把431内素数都打出来,再建表,把432内每个数字阶乘需要的素因数个数打出来,然后根据公式计算即可。
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstring>
using namespace std;
int main()
{
int i,j,n,k,a[432][432]={0},prime[432],num,re[432];
bool b[432]={0};
long long sum=1;
b[1]=1;
for(i=2,num=0;i<432;i++)
{
if(b[i]==0)
{
prime[num]=i;
num++;
for(int j=i*i;j<432;j+=i){
b[j]=1;}
}
}
for(int i=2;i<432;i++)
{
k=i;
for(int j=0;j<num;j++)
{
while(k%prime[j]==0&&k>1)
{
a[i][j]++;
k/=prime[j];
}
a[i][j]+=a[i-1][j];
}
}
while(~scanf("%d%d",&n,&k))
{
sum=1;
if(k==0||n==k)
cout<<1<<endl;
else{
for(int i=0;i<=n;i++)
{
sum*=(1+a[n][i]-a[k][i]-a[n-k][i]);
}
printf("%lld\n",sum);
}}
return 0;
}