poj 2992 Divisors 筛法 算术基本定理

poj 2992 Divisors 筛法 算术基本定理
Divisors
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 11340 Accepted: 3376

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<iostream>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define LL long long
#define M 432
using namespace std;

struct m
{
    int a[83];
} q[432];

bool visit[M];
int p[M];
int np=0;
void ddd()
{
    memset(visit,1,sizeof(visit));
    for(int i=2; i<M; ++i)
    {
        if(visit[i]==1)
        {
            p[np++]=i;
            for(int j=i*i; j<M; j+=i)
            {
                visit[j]=0;
            }
        }
    }
}
void iii()
{
    int t,i,w,j,d;
    for(i=0; i<83; i++)
        q[0].a[i]=0;
    for(i=1; i<=432; i++)
    {
        t=i;
        for(w=0; w<=82; w++)
            q[i].a[w]=q[i-1].a[w];

        for(j=0; p[j]<=i; j++)
        {
            while(t%p[j]==0)
            {
                q[i].a[j]++;
                t/=p[j];
            }
            if(t==1) break;
        }
    }
}
int main()
{
    ddd();
    iii();
    LL  ans;
    int i,b,t,a;
    while(~scanf("%d %d",&a,&b))
    {
        t=a-b;
        ans=1;
        int x=a>82?82:a;
        for(i=0; i<=x; i++)
            ans*=(1+(long long )q[a].a[i]-q[b].a[i]-q[t].a[i]);
        printf("%lld\n",ans);
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值