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

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

Source

 
 
 /*
题意: 求 组合数 C(n,m)= n! / ( (n - m)! * m! ) 的 因数 个数,n<=431 设 n 的标准质因数分解式为 n = p1^a1 * p2^a2 *...* pk^ak , p1,p2..pk是素数
则 n 的 因数 个数 = (a1+1) * (a2+1) *...* (ak+1)
对于任意素数 p ,n!中有( n / p + n / p^2 + n / p^3 +...)个质因子 p
思路: 先打素数表,再对每个素数p求在C(n,m)的个数a,相乘即得结果 */ /*
1.
C(n,m)= n! / ( (n - m)! * m! ) 枚举求解对于每一个素数因子。
居然可以这样。
ans=fun(n,prime[i])-fun(n-m,prime[i])-fun(m,prime[i]);
仔细想想,感觉..哈哈。
2.还有一点,要提。因为本人书写的习惯很差,所以经常在遇到要用__int64 的时候
就全部都用了。这题数据很好,就卡在这了好几处。超时...
其实在素数打表的过程中,我们也有体会,用bool的速度远远要小于标记用int的速度。 */ #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std; bool s[];
int prime[],len; void make_prime()
{
int i,j;
for(i=;i<=;i++)
s[i]=false;
len=; for(i=;i<=;i++)
if(s[i]==false)
{
prime[++len]=i;
for(j=i*;j<=;j=j+i)
s[j]=true;
}
} int fun(int n,int s)
{
int ans=;
while(n)
{
n=n/s;
ans=ans+n;
}
return ans;
} int main()
{
make_prime();
int n,m,i,ans;
__int64 sum;
while(scanf("%d%d",&n,&m)>)
{
sum=;
for(i=;i<=len;i++)
{
if(prime[i]>n)break;
ans=fun(n,prime[i])-fun(n-m,prime[i])-fun(m,prime[i]);
sum=sum*(ans+);
}
printf("%I64d\n",sum);
}
return ;
}

poj 2992 Divisors (素数打表+阶乘因子求解)的更多相关文章

  1. uva11610 树状数组+素数打表求因子,好题!

    /* uva11610 树状数组+素数打表+离散化 打出的素数范围在2-1000000之间,不超过六位数,然后按照格式翻转成七位数 */ #include<bits/stdc++.h> u ...

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

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

  3. POJ 2992 Divisors

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

  4. poj 2992 Divisors 整数分解

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

  5. HDU 2136 素数打表+求质数因子

    Largest prime factor Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  6. POJ 1595 Prime Cuts (ZOJ 1312) 素数打表

    ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=312 POJ:http://poj.org/problem?id=159 ...

  7. [ACM] POJ 2635 The Embarrassed Cryptographer (同余定理,素数打表)

    The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11978   A ...

  8. POJ 2739 Sum of Consecutive Prime Numbers【素数打表】

    解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memo ...

  9. hdu 5104 素数打表水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5104 找元组数量,满足p1<=p2<=p3且p1+p2+p3=n且都是素数 不用素数打表都能过,数据 ...

随机推荐

  1. 《快学Scala》第五章 类

    关于case class和普通class的区别,可以参考: https://www.iteblog.com/archives/1508.html

  2. PHP之旅 php数据类型

    1.php中int型,表示八进制或十六进制或者十进制时的不同,八进制前面加0,十六进制前面加0x <?php $dec_int=99; $oct_int=066; $hex_int=0X1a; ...

  3. drools入门示例

    Drools是一个基于java的规则引擎,开源的,可以将复杂多变的规则从硬编码中解放出来,以规则脚本的形式存放在文件中,使得规则的变更不需要修正代码重启机器就可以立即在线上环境生效.随着互联网金融的兴 ...

  4. delphi 10.2 ----简单的递归函数例子求和

    unit Unit10; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, Syste ...

  5. 编译原理(六)自底向上分析之LR分析法

    自底向上分析之LR分析法 说明:以老师PPT为标准,借鉴部分教材内容,AlvinZH学习笔记. 基本概念 1. LR分析:从左到右扫描(L)自底向上进行规约(R),是规范规约,也即最右推导(规范推导) ...

  6. (C/C++) string / *char / int 基本轉換

    網路上有許 string / *char / integer 基本轉換方式 string 與 *char 互相轉換的方法 /* string to *char */ string ssbuf1 = & ...

  7. 对 ArrayList 进行分页.

    /** * 测试分页 */ @Test public void testPage() { int bulkSize = 2; List<Integer> dataList = new Ar ...

  8. 数组或者stack

    数组 clear1(long long int array[], size_t int size) { ; i < size; i += ) array[i] = ; } li x5, // i ...

  9. 南昌网络赛 Distance on the tree 主席树+树剖 (给一颗树,m次查询ui->vi这条链中边权小于等于ki的边数。)

    https://nanti.jisuanke.com/t/38229 题目: 给一颗树,m次查询ui->vi这条链中边权小于等于ki的边数. #include <bits/stdc++.h ...

  10. 【性能测试】脚本开发,最普通的http协议脚本2

    Action() { lr_start_transaction("FM0075基金购买"); web_submit_data("ehouse_ehGetPwdRandom ...