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 263 - 1.

Sample Input

5 1
6 3
10 4

Sample Output

2
6
16

【题意】求C(n,m)的质因子的个数。

【定理】设正整数n的所有素因子分解n=p1^a1*p2^a2*p3^a3****ps^as,那么T(n)=(a1+1)*(a2+1)*(a3+1)***(an+1);(求因子的个数的公式)

1.求出N以内素数

2.ei=[N/pi^1]+ [N/pi^2]+ …… + [N/pi^n] 其中[]为取整。即可以 int ei=0;while(N) ei+=(N/=pi);

3.套公式计算了,M=(e1+1)*(e2+1)*……*(en+1)

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int N=;
int prime[]={,,};
int k=;
long long n,m,cnt[N][N];
void get_prime()//将1000以内的素数存入prime数组;
{
int flag;
int p=;
for(int i=;i<=;i+=p)
{
flag=;
p=-p;//巧妙的跳过了3的倍数,提高了效率
for(int j=;prime[j]*prime[j]<=i;j++)
{
if(i%prime[j]==)
{
flag=;
break;
}
}
if(!flag) prime[k++]=i;
}
}
void init()
{
memset(cnt,,sizeof(cnt));
get_prime();
long long tmp,ret;
for(int i=;i<=;i++)
{
for(int j=;prime[j]<=i;j++)
{
tmp=i;
ret=;
while(tmp)
{
tmp=tmp/prime[j];
ret+=tmp;
}
cnt[i][prime[j]]=ret;//i的质因子数
}
}
}
int main()
{
init();
long long ret,ans;
while(~scanf("%lld%lld",&n,&m))
{
ans=;
for(int i=;prime[i]<=n;i++)
{
ret=cnt[n][prime[i]]-cnt[m][prime[i]]-cnt[n-m][prime[i]];//c(n,m)=n!/((n-m)!m!),把对应因子个数相减,我们就得到了c(n,m)分解的结果
ans*=(ret+);
}
printf("%lld\n",ans);
}
return ;
}

Divisors_组合数因子个数的更多相关文章

  1. Divisors (求解组合数因子个数)【唯一分解定理】

    Divisors 题目链接(点击) Your task in this problem is to determine the number of divisors of Cnk. Just for ...

  2. LightOj1028 - Trailing Zeroes (I)---求因子个数

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1028 题意:给你一个数 n (1<=n<=10^12), 然后我们可以把它 ...

  3. POJ 2992 求组合数的因子个数

    求C(n,k)的因子个数 C(n,k) = (n*(n-1)*...*(n-k+1))/(1*2*...*k) = p1^k1 * p2^k2 * ... * pt^kt 这里只要计算出分子中素数因子 ...

  4. POJ 2992 Divisors (求因子个数)

    题意:给n和k,求组合C(n,k)的因子个数. 这道题,若一开始先预处理出C[i][j]的大小,再按普通方法枚举2~sqrt(C[i][j])来求解对应的因子个数,会TLE.所以得用别的方法. 在说方 ...

  5. HDOJ(HDU) 2521 反素数(因子个数~)

    Problem Description 反素数就是满足对于任意i(0< i < x),都有g(i) < g(x),(g(x)是x的因子个数),则x为一个反素数.现在给你一个整数区间[ ...

  6. Easy Number Challenge(暴力,求因子个数)

    Easy Number Challenge Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  7. Acdream1084 寒假安排 求n!中v因子个数

    题目链接:pid=1084">点击打开链接 寒假安排 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 128000/64000 ...

  8. CodeForces 546D Soldier and Number Game 打表(求质因子个数)

    题目:戳我这个题与HDUOJ 5317有异曲同工之妙 题意:题意看懂了上面的一大串英文之后其实很简单,就是给你一个正整数n,问你n有多少个质因子,不过这里n是通过a!/b!给定的,也就是说n=(a!/ ...

  9. Factors of Factorial AtCoder - 2286 (N的阶乘的因子个数)(数论)

    Problem Statement You are given an integer N. Find the number of the positive divisors of N!, modulo ...

随机推荐

  1. hdu----(1677)Nested Dolls(DP/LIS(二维))

    Nested Dolls Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  2. hdu------(1757)A Simple Math Problem(简单矩阵快速幂)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  3. java中的if-Switch选择结构

    字随笔走,笔随心走,随笔,随心.纯属个人学习分析总结,如有观者还请不啬领教. 1.if选择结构 什么是if结构:if选择结构是根据判断结果再做处理的一种语法结构. 起语法是: if(判断条件){ 操作 ...

  4. mouseover和mouseout多次触发解决方法(兼容ie和firefox)(转)

    在用到mouseover和mouseout事件来作为事件触发的条件,但是如果我们用做触发的元素内部有其他的元素的时候当鼠标移上的时候会反复的触发mouseover和mouseout事件,如导致菜单闪烁 ...

  5. Error initializing endpoint java.lang.Exception: Socket bind failed: [730048] ?????????×???(Э?é/???????/???)????í??

    2010-5-18 22:00:38 org.apache.catalina.core.AprLifecycleListener lifecycleEvent 信息: The Apache Tomca ...

  6. Understanding Virtual Memory

    Understanding Virtual Memory by Norm Murray and Neil Horman Introduction Definitions The Life of a P ...

  7. bzoj 1997: [Hnoi2010]Planar

    #include<cstdio> #include<cstring> #include<iostream> #define M 20005 #define N 20 ...

  8. ASP.NET MVC 基于角色的权限控制系统的示例教程

    上一次在 .NET MVC 用户权限管理示例教程中讲解了ASP.NET MVC 通过AuthorizeAttribute类的OnAuthorization方法讲解了粗粒度控制权限的方法,接下来讲解基于 ...

  9. python下的复杂网络编程包networkx的安装及使用

    由于py3.x与工具包的兼容问题,这里采用py2.7 1.python下的复杂网络编程包networkx的使用: http://blog.sina.com.cn/s/blog_720448d30101 ...

  10. 数据结构-Hash表

    实现: #ifndef SEPARATE_CHAINING_H #define SEPARATE_CHAINING_H #include <vector> #include <lis ...