POJ 2992 Divisors[组合数 因子个数]

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;
}
 

转载于:https://www.cnblogs.com/dream-wind/archive/2012/03/17/2403903.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值