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

  1. 5 1
  2. 6 3
  3. 10 4

Sample Output

  1. 2
  2. 6
  3. 16
  4.  
  5. 思路:求因数个数,想到唯一分解定理
    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+....
  1. typedef long long LL;
  2. typedef pair<LL, LL> PLL;
  3.  
  4. const int maxm = ;
  5.  
  6. bool prime[maxm];
  7. int num[maxm][maxm];
  8. int jud[maxm], siz = ;
  9. LL C[maxm][maxm];
  10.  
  11. void getprime() {
  12. for(int i = ; i * i <= maxm; ++i) {
  13. if(!prime[i]) {
  14. for(int j = i*i; j <= maxm; j += i)
  15. prime[j] = true;
  16. }
  17. }
  18. for(int i = ; i <= maxm; ++i)
  19. if(!prime[i]) {
  20. jud[siz++] = i;
  21. }
  22. for(int i = ; i < siz; ++i) {
  23. for(int j = ; j <= maxm; ++j)
  24. num[j][i] = j/jud[i] + num[j/jud[i]][i];
  25. }
  26. for(int i = ; i <= maxm; ++i) { // C[i][j]
  27. for(int j = ; j < i; ++j) {
  28. C[i][j] = ;
  29. for(int k = ; k < siz; ++k) {
  30. int d = num[i][k] - num[i-j][k] - num[j][k];
  31. if(d) C[i][j] *= (d+);
  32. }
  33. }
  34. }
  35. }
  36.  
  37. int main() {
  38. getprime();
  39. int n, k;
  40. while(scanf("%d%d", &n, &k) != EOF) { // C(n, k) n!/k!(n-k)!
  41. if(n == k || k == )
  42. printf("1\n");
  43. else
  44. printf("%lld\n", C[n][k]);
  45. }
  46. return ;
  47. }
  1.  

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. Write-up-Violator

    关于 下载地址:点我 Flag:/root/flag.txt 哔哩哔哩:视频 信息收集 网卡:虚拟机vmnet8 ➜ ~ ip addr show dev vmnet8 5: vmnet8: < ...

  2. Swift3.0-基本运算符

    一.简介 运算符是检查.改变.合并值的特殊符号或者短语.在本篇文章中只介绍基本运算符,Swift中包含的高级运算符(比如溢出运算符)不在其中.Swift中的运算符和OC中的运算法还是有比较大的区别的, ...

  3. Unity热更新对比

    https://www.jianshu.com/p/f9d90edf4a7c Unity 热更新为啥用Lua 详解 ILRuntime的优势 同市面上的其他热更方案相比,ILRuntime主要有以下优 ...

  4. VS误删sln项目文件怎么办

    以项目名为Test为例 打开Test/Test目录下的 Test.vcxproj 文件,试着运行一下,退出后提示保存sln文件,选择一个目录即可.

  5. PTA的Python练习题(十一)

    从 第4章-3 猴子吃桃问题 继续 1. a=eval(input()) def count(n): b=1 for i in range(n-1): b=(b+1)*2 return b print ...

  6. PTA的Python练习题(七)

    不知不觉一个星期过去了,继续从 第3章-12 求整数的位数及各位数字之和 开始做题 1. 我原来想用题目漏洞做题的,不过想想还是算了自己写个完整的: a=int(input()) b=len(str( ...

  7. 3_04_MSSQL课程_Ado.Net_.ExcuteReader()(SQLDataReader)

    ExcuteNonQuery(); 返回影响的行数 ExcuteSacalar();返回第一行第一列 ExcuteReader(): Reader,指针,指向表的表头.只是指向,数据仍在数据库中. S ...

  8. Codeforces Round #586 (Div. 1 + Div. 2)D(二分图构建,思维,结论需数论证明)

    #include<bits/stdc++.h>using namespace std;long long a[200007];vector<int>v[77];int main ...

  9. 本周总结(19年暑假)—— Part1

    日期:2019.7.14 博客期:107 星期日 这几周正在摸索着找寻与大型数据库相关的知识,重装了电脑,配置了虚拟机的环境,继续研究了几下修改器.

  10. windows索引服务

        windows索引服务是windows操作系统提供的桌面搜索引擎,通过预先创建索引来提高对硬盘上文件内容的搜索速度.以windows服务程序的方式运行. 一.工作方式 1.对指定路径下的文件创 ...