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. hdu1710(Binary Tree Traversals)(二叉树遍历)

    Binary Tree Traversals Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  2. C#中DateTime应用

    编写一个控制台程序,输入一个日期,求下一天的日期. 要求如下:在控制台输入一个日期(分别输入年.月.日),判断输入的日期是否有效,如果有效,计算该日期的下一天日期,并显示:否则,输出"无效的 ...

  3. Pinyin4Net

    .net使用的汉字转拼音库.Pinyin4Net 是直接从 Pinyin4J 翻译过来的,很多代码甚至是直接copy的. 用法与pinyin4j完全相同,具体请查阅pinyin4j文档. —— 查看更 ...

  4. 算法——js(Fibonacci数列)

    斐波那契数列(Fibonacci sequence),又称黄金分割数列,因数学家列昂纳多·斐波那契(Leonardoda Fibonacci[1]  )以兔子繁殖为例子而引入,故又称为“兔子数列”,指 ...

  5. 隐藏chrome空白标签栏的最近访问

    chrome版本: 29.0.1547.76 m 找到安装路径下Custom.css文件,添加.most-visited{display:none !important}来修改样式. 我的路径为:C: ...

  6. android webview web里面的数据透传到java以及java的数据透传到web

    详见: http://tutorials.jenkov.com/android/android-web-apps-using-android-webview.html#android-web-app- ...

  7. C# 检测网络链接

    ;//Local system uses a modem to connect to the Internet. ; //Local system uses a local area network ...

  8. Windows获取文件大小

    Windows最初的设计允许我们处理非常大的文件,所以最初的设计者选用64位值来表示文件大小.但是我们在日常处理过程中文件大小一般不会超过4GB.故Windows提供了两个联合类型的数据结构表示文件大 ...

  9. git常用语法

    git笔记  1.     获取项目(克隆):     Git repository:                       git clone -b develop ssh://git@68. ...

  10. static方法,属性,代码块初始化顺序和执行顺序

    http://greateryang.blog.163.com/blog/static/81953375201232621031508/