POJ 2992

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值