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 思路:求因数个数,想到唯一分解定理
p = a1^s1+a2^s2+...., 因子总数=(s1+1)(s2+1)..... 每次都计算组合数再计算因子数显然会超时,范围只有431,可以预处理
先预处理出质数,由C[n][m] = n!/m!(n-m)!, 将每个阶乘中的质因子次数求出来,例如对于n!,求质数i的次数 = n/i+n/i^2+n/i^3+....
递推优化, a = n/i+n/i^2+...., b = a / i = n/i^2+n/i^3+....
typedef long long LL;
typedef pair<LL, LL> PLL; const int maxm = ; bool prime[maxm];
int num[maxm][maxm];
int jud[maxm], siz = ;
LL C[maxm][maxm]; void getprime() {
for(int i = ; i * i <= maxm; ++i) {
if(!prime[i]) {
for(int j = i*i; j <= maxm; j += i)
prime[j] = true;
}
}
for(int i = ; i <= maxm; ++i)
if(!prime[i]) {
jud[siz++] = i;
}
for(int i = ; i < siz; ++i) {
for(int j = ; j <= maxm; ++j)
num[j][i] = j/jud[i] + num[j/jud[i]][i];
}
for(int i = ; i <= maxm; ++i) { // C[i][j]
for(int j = ; j < i; ++j) {
C[i][j] = ;
for(int k = ; k < siz; ++k) {
int d = num[i][k] - num[i-j][k] - num[j][k];
if(d) C[i][j] *= (d+);
}
}
}
} int main() {
getprime();
int n, k;
while(scanf("%d%d", &n, &k) != EOF) { // C(n, k) n!/k!(n-k)!
if(n == k || k == )
printf("1\n");
else
printf("%lld\n", C[n][k]);
}
return ;
}
												

Day7 - G - Divisors POJ - 2992的更多相关文章

  1. A - Divisors POJ - 2992 (组合数C的因子数)数学—大数

    题意:就是求组合数C的因子的个数! 先说一下自己THL的算法,先把组合数求出来,然后将这个大数分解,得到各个素数的个数,再利用公式!用最快的大数分解算法 分析一下时间复杂度!   n1/4但是分析一下 ...

  2. poj 2992 Divisors (素数打表+阶乘因子求解)

    Divisors Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9617   Accepted: 2821 Descript ...

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

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

  4. POJ 2992 Divisors

    每个数都可以分解成素数的乘积: 写成指数形式:n=p1^e1*p2^e2*...*pn^en:(p都是素数) 那么n的因数的数量m=(e1+1)*(e2+1)*...*(en+1): 所以用筛选法筛出 ...

  5. poj 2992 Divisors 整数分解

    设m=C(n,k)=n!/((n-k)!*k!) 问题:求m的因数的个数 将m分解质因数得到 p1有a1个 p2有a2个 .... 因为每一个质因数能够取0~ai个(所有取0就是1,所有取ai就是m) ...

  6. poj 2992

    http://poj.org/problem?id=2992 大意:求(n,k)的因子个数 解题思路:(n,k) = n!/(k!(n-k)!)  任意一个数都可以用其质因子来表示  eg: 26 = ...

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

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

  8. Day7 - K - Biorhythms POJ - 1006

    Some people believe that there are three cycles in a person's life that start the day he or she is b ...

  9. OJ提交题目中的语言选项里G++与C++的区别(转)

    G++? 首先更正一个概念,C++是一门计算机编程语言,G++不是语言,是一款编译器中编译C++程序的命令而已. 那么他们之间的区别是什么? 在提交题目中的语言选项里,G++和C++都代表编译的方式. ...

随机推荐

  1. UIKit框架使用总结--看看你掌握了多少

    一.经常使用的,基本就是每次项目迭代都需要使用的 UIView.UILabel.UIImage.UIColor.UIFont.UIImageView.UITextField.UIButton. UIS ...

  2. 关于TXT文件中英文单词出现频率排序问题

    题目要求: 指定文件目录, 但是会递归遍历目录下的所有子目录,输出文件中所有不重复的单词,按照出现次数由多到少排列. 源码: package word; import java.io.File;  i ...

  3. 牛茶冲天的ip命令

    一.修改二层链路相关设置 1.修改网卡名称(修改前要先停止) ip link set eth0 name  testname 2.修改网卡地址 ip link set eth0 address xxx ...

  4. 10 JavaScript对象&类&for循环

    JavaScript对象 JavaScript中所有事物都是对象:字符串.数值.数组.函数.数学和正则表达式 JavaScript有些类型可以是字面量而非对象:如字符串.数值.布尔值 JavaScri ...

  5. 吴裕雄--天生自然ORACLE数据库学习笔记:Oracle数据备份与恢复

    run{ allocate channel ch_1 device type disk format = 'd:\oraclebf\%u_%c.bak'; backup tablespace syst ...

  6. js运动框架及应用

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  7. 第3节 Scala中的模式匹配:1 - 5

    7.    模式匹配和样例类 Scala有一个十分强大的模式匹配机制,可以应用到很多场合:如switch语句.类型检查等.并且Scala还提供了样例类,对模式匹配进行了优化,可以快速进行匹配. 7.1 ...

  8. eclipse启动时权限不够的问题

    eclipse启动时权限不够的问题 2009年04月28日 19:19:00 tomey21 阅读数 1445   安装好后每次都要用root权限运行,比较郁闷,摸索了一下,修改一下相关目录的权限就可 ...

  9. AngularJS四大特征

    AngularJS四大特征 1.MVC模式 Angular遵循软件工程的MVC模式,并鼓励展现,数据,和逻辑组件之间的松耦合.通过依赖注入(dependency injection),Angular为 ...

  10. 138、Java内部类之访问内部类的私有属性

    01.代码如下: package TIANPAN; class Outer { // 外部类 private String msg = "Hello World !"; class ...