poj 2992 Divisors(求因子个数)

Language:
Divisors
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 10784 Accepted: 3193

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



求组合数因子个数

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <queue>

#define MEM(a,x) memset(a,x,sizeof a)
#define eps 1e-8
#define MOD 10009
#define MAXN 10010
#define MAXM 100010
#define INF 99999999
#define ll __int64
#define bug cout<<"here"<<endl
#define fread freopen("ceshi.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)

using namespace std;

int Read()
{
    char ch;
    int a = 0;
    while((ch = getchar()) == ' ' | ch == '\n');
    a += ch - '0';
    while((ch = getchar()) != ' ' && ch != '\n')
    {
        a *= 10;
        a += ch - '0';
    }
    return a;
}

void Print(int a)    //Êä³öÍâ¹Ò
{
     if(a>9)
         Print(a/10);
     putchar(a%10+'0');
}

ll ans[432][432];
void init()
{
    bool prime[440];
    int p[100],num=0;
    MEM(prime,0);
    for(int i=2;i<440;i++)
    {
        if(!prime[i])  p[num++]=i;
        for(int j=0;j<num&&i*p[j]<440;j++)
        {
            prime[i*p[j]]=1;
            if(!(i%p[j])) break;
        }
    }//筛素数
    int fac[440][100];
    MEM(fac,0);
    for(int i=0;i<num;i++)
    {
        for(int j=2;j<440;j++)
            fac[j][i]=j/p[i]+fac[j/p[i]][i];
    }//阶乘分解为 几个素数的乘积
    for(int i=2;i<432;i++)
    {
        for(int j=1;j<i;j++)
        {
            ans[i][j]=1;
            for(int k=0;k<num&&fac[i][k];k++)
            {
                int s=fac[i][k]-fac[j][k]-fac[i-j][k];
                if(s)
                    ans[i][j]*=(s+1);//因子个数
            }
        }
    }
}

int main()
{
    //fread;
    int n,k;
    init();
    while(scanf("%d%d",&n,&k)!=EOF)
    {
        if(k==0||k==n)
        {
            puts("1");
            continue;
        }
        printf("%I64d\n",ans[n][k]);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值