POJ 2992 Divisors

Divisors
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 11810 Accepted: 3523

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

Source


题意:求组合数C(k,n)的因子有多少个
很明显要用到唯一分解定理,不打表直接计算肯定超时,可以计算从n到n-k+1的各因子数之和减去1到n的因子之和,再按照唯一分解定理的公式即可,注意结果输出会爆int,要用到long long

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<cmath>
#include<vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;

#define pi acos(-1.0)
#define eps 1e-10
#define pf printf
#define sf scanf
#define lson rt<<1,l,m
#define rson rt<<1|1,m+1,r
#define e tree[rt]
#define _s second
#define _f first
#define all(x) (x).begin,(x).end
#define mem(i,a) memset(i,a,sizeof i)
#define for0(i,a) for(int (i)=0;(i)<(a);(i)++)
#define for1(i,a) for(int (i)=1;(i)<=(a);(i)++)
#define mi ((l+r)>>1)
#define sqr(x) ((x)*(x))

const int inf=0x3f3f3f3f;
int p[432/2],m,n,n1[435],n2[435];
bool vis[432];
ll ans[435][300];

void prime()//素数打表,O(n(log n)),O(n),O(n*sqrt(n))均可
{
    mem(vis,0);
    p[0]=0;
    for(int i=2;i<=432;i++)
    {
        if(!vis[i])p[++p[0]]=i;
        for(int j=1;j<=p[0]&&(ll)i*p[j]<=432;j++)
        {
            vis[i*p[j]]=1;
            if(!(i%p[j]))break;
        }
    }
}

void fenjie(int m,int num[])//唯一分解
{
    for(int i=1;i<=p[0]&&(ll)p[i]*p[i]<=m;i++)
    {
        while(!(m%p[i]))
            num[p[i]]++,m/=p[i];
    }
    if(m>1)num[m]++;
}

void init()//打表计算所有结果
{
    for(int i=0;i<=431;i++)//防止出现n为0的情况
        for(int j=0;j<=299;j++)
            ans[i][j]=1;
    for(int i=2;i<=432;i++)
    {
        mem(n1,0);
        mem(n2,0);
        for(int j=1;j<=i>>1;j++)
        {
            fenjie(i-j+1,n1);
            fenjie(j,n2);
            for(int k=1;k<=432;k++)
                ans[i][j]*=(n1[k]-n2[k]+1);
        }
    }
}

int main()
{
    prime();
    init();
    while(~sf("%d%d",&m,&n))
    {
        n=min(n,m-n);
        pf("%lld\n",ans[m][n]);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值