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. java SE学习之线程同步(详细介绍)

           java程序中可以允许存在多个线程,但在处理多线程问题时,必须注意这样一个问题:               当两个或多个线程同时访问同一个变量,并且一些线程需要修改这个变量时,那么这个 ...

  2. 探究linux文件

    一.Linux的文件: 文件名区分大小写:Linux没有文件拓展名:文件名支持长文件名,含空格,少部分标点符号. - _最好不要用空格 1 GUI图形用户界面:让简单的问题更加简单: CLI命令行界面 ...

  3. DOM中元素节点、属性节点、文本节点的理解

    DOM中元素节点.属性节点.文本节点的理解 节点信息 每个节点都拥有包含着关于节点某些信息的属性.这些属性是:nodeName(节点名称) nodeValue(节点值) nodeType(节点类型)  ...

  4. SASS学习笔记2 —— 语法

    sass有两种后缀名文件:一种后缀名为sass,不使用大括号和分号:另一种是scss文件,这种和我们平时写的css文件格式差不多,使用大括号和分号.在此也建议使用后缀名为scss的文件,以避免sass ...

  5. [转]Web基础架构:负载均衡和LVS

    以下内容转载自:http://www.importnew.com/11229.html 在大规模互联网应用中,负载均衡设备是必不可少的一个节点,源于互联网应用的高并发和大流量的冲击压力,我们通常会在服 ...

  6. 转:Oracle中的rownum不能使用大于>的问题

    一.对rownum的说明 关于Oracle 的 rownum 问题,很多资料都说不支持SQL语句中的“>.>=.=.between...and”运算符,只能用如下运算符号“<.< ...

  7. bzoj 1951: [Sdoi2010]古代猪文

    #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #defin ...

  8. 【STL】-auto_ptr的用法

    初始化: #include<memory> //auto_ptr header void f() { auto_ptr<classA> ptr(new classA); } 拷 ...

  9. DotNetBar v12.9.0.0 Fully Cracked

    更新信息: http://www.devcomponents.com/customeronly/releasenotes.asp?p=dnbwf&v=12.9.0.0 如果遇到破解问题可以与我 ...

  10. jQuery Ajax之load()方法

    jQuery对Ajax操作进行了封装,在jQuery中$.ajax()方法属于最底层的方法,第2层是load().$.get()和$.post()方法,第3层是$.getScript()和$.getJ ...