POJ 2992 Divisors(求组合数因子个数)

Divisors
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 12048 Accepted: 3594

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

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top


题意:求C(n,k)的因子个数。

题解:C(n,k)=n!/k!/(n-k)!,直接将所有阶乘的数分解出所有素因数然后统计一下

然后套用因数个数公式就好   (p1+1)*(p2+1)*(p3+1)*...*(pn+1)

题目很简单,然而卡时间,500*50*50都卡??

好吧,预处理一下就OK了。。。。。

定义dp[i][j]:表示i的阶乘里有几个素数j。

#include<set>      
#include<map>         
#include<stack>                
#include<queue>                
#include<vector>        
#include<string>     
#include<time.h>    
#include<math.h>                
#include<stdio.h>                
#include<iostream>                
#include<string.h>                
#include<stdlib.h>        
#include<algorithm>       
#include<functional>        
using namespace std;                
#define ll long long          
#define inf 1000000000           
#define mod 1000000007                
#define maxn  50500    
#define lowbit(x) (x&-x)                
#define eps 1e-9  
ll a[505]={1,1},b[500];
ll dp[450][450],cnt;
void init()
{
	ll i,j;
	for(i=2;i<=432;i++)
	{
		if(a[i])
			continue;
		b[++cnt]=i;
		for(j=i*i;j<=432;j+=i)
			a[j]=1;
	}
	for(i=2;i<=432;i++)
	{
		for(j=1;b[j]<=i && j<=cnt;j++)
		{
			ll tmp=i,res=0;
			while(tmp)
				tmp/=b[j],res+=tmp;
			dp[i][b[j]]=res;
		}
	}
}
int main(void)
{
	init();
	ll i,x,y;
	while(scanf("%lld%lld",&x,&y)!=EOF)
	{
		ll ans=1;
		for(i=1;b[i]<=x && i<=cnt;i++)
		{
			ll tmp=dp[x][b[i]]-dp[y][b[i]]-dp[x-y][b[i]];
			ans=ans*(tmp+1);
		}
		printf("%lld\n",ans);
	}
	return 0;
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值