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. JavaScrip的DOM操作(13号讲)

    1.DOM的基本概念 DOM是文档对象模型,这种模型为树模型,文档是指标签文档:对象是指文档中每个元素:模型是指抽象化的东西 2.Windows对象操作 一.属性和方法 二.Window.open(& ...

  2. [转]RAID技术介绍和总结

    以下内容转自伯乐在线:http://blog.jobbole.com/83808/ 原文出处: 涯余(@若东临于沧海) ---------------------------------------- ...

  3. Java: constructor 构造代码块

    构造器与类同名 每个类可以有1一个以上的构造器 构造器可以有0个,1个或者多个参数 构造器没有返回值,不可以写return 构造器总是伴随着new操作一起调用 构造函数的作用:可以用于给对象进行初始化 ...

  4. ASP.NET MVC的Ajax.ActionLink 的HttpMethod="Get" 一个重复请求的BUG

    这段时间使用BootStrap+Asp.net Mvc5开发项目,Ajax.ActionLink遇到一个重复提交的BUG,代码如下: @model IList<WFModel.WF_Temp&g ...

  5. 利用LM神经网络和决策树去分类

    # -*- coding: utf-8 -*- import pandas as pd from scipy.interpolate import lagrange from matplotlib i ...

  6. a标签的css样式四个状态的设计

    表示所有状态下的连接 如 a{color:red} ① a:link:未访问链接 ,如 a:link {color:blue} ② a:visited:已访问链接 ,如 a:visited{color ...

  7. Codeforces Round #257 (Div. 1) (Codeforces 449D)

    思路:定义f(x)为 Ai & x==x  的个数,g(x)为x表示为二进制时1的个数,最后答案为    .为什么会等于这个呢:运用容斥的思想,如果 我们假设 ai&x==x 有f(x ...

  8. svn cleanup failed问题解决

    1.SVN出错 今早过来Update,报如下错误: 再次更新,svn会要求你执行clean up,但执行clean up仍会报错,说有未完的work item,还要求你执行clean up.汗,陷入死 ...

  9. IT公司100题-18-圆圈中最后剩下的数字

    问题描述: n个数字(下标为0, 1, …, n-1)形成一个圆圈,从数字0开始,每次从这个圆圈中删除第m个数字(当前数字从1开始计数).当一个数字被删除后,从被删除数字的下一个数字开始计数,继续删除 ...

  10. HDU 1693 二进制表示的简单插头dp

    题目大意: 找到多条回路覆盖所有非障碍格子,问这样回路的种数 这里的插头与URAL1519 不一样的是 只要管它是否存在即可,只需要1个二进制位表示状态 #include <cstdio> ...