Time Limit: 5000 ms    Memory Limit: 10000 kB  
Total Submit : 432 (78 users)   Accepted Submit : 108 (57 users)   Page View : 3479  Font Style: Aa Aa Aa
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 4Sample Output
2
6
16

代码如下:12=2^2*3^1 因子个数就等于(2+1)*(1+2)=12

#include<iostream>
#include<cstdio>
using namespace std;
int num;
bool a[]; struct prime
{
int num;
int count;
}p[]; void init()
{
int i,j;
memset(a,true,sizeof(a));
num=;
for(i=;i<;i++)
{
if(a[i]) p[num++].num=i;
for(j=;j<num&&i*p[j].num<;j++)
{
a[p[j].num*i]=;
if(i%p[j].num==)
break;
}
}
} __int64 Deal(int n,int m)
{
int i,j;
int a,b;
__int64 sum=;
if(m*<n)
a=n,b=n-m;
else
a=n,b=m;
for(i=;i<num;i++)
p[i].count=;
for(i=b+;i<=a;i++)
{
int t=i;
for(j=;p[j].num<=i && j<num && t!=;j++)
{
while(t%p[j].num==)
{
t/=p[j].num;
p[j].count++;
}
}
}
for(i=;i<=a-b;i++)
{
int t=i;
for(j=;p[j].num<=i && j<num && t!=;j++)
{
while(t%p[j].num==)
{
t/=p[j].num;
p[j].count--;
}
}
}
for(i=;i<num;i++)
{
if(p[i].count)
sum*=(p[i].count+);
}
return sum;
} int main()
{
int n,m;
init();
while(cin>>n>>m)
printf("%I64d\n",Deal(n,m));
return ;
}

Nk 1430 Divisors(因子数与质因数)的更多相关文章

  1. HDU6069:Counting Divisors(因子数统计|区间筛)

    题意 计算\(\sum_{i=l}^kd(i^k)(d_i代表i的因子数)\) 分析 比赛搞了3个小时都没搞出来,有两个思维上的trick 1.要先遍历素数,再遍历[L,R],而不是枚举每个数,然后对 ...

  2. Nk 1430 Fibonacci(二分矩阵乘幂)

    AC代码: #include<iostream> using namespace std; ][]; ][]; ][]; ][]; void binary(int n) { int i,j ...

  3. 从“n!末尾有多少个0”谈起

    在学习循环控制结构的时候,我们经常会看到这样一道例题或习题.问n!末尾有多少个0?POJ 1401就是这样的一道题. [例1]Factorial (POJ 1401). Description The ...

  4. Day 2 T1

    题目描述 组合数表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三个物品中选择两个物品可以有(1,2),(1,3),(2,3)这三种选择方法.根据组合数的定 义,我们可以给出计算 ...

  5. 2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)

    题目链接 Problem Description In mathematics, the function d(n) denotes the number of divisors of positiv ...

  6. HDU 6069 Counting Divisors(唯一分解定理+因子数)

    http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...

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

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

  8. 【线性筛】【质因数分解】【约数个数定理】hdu6069 Counting Divisors

    d(x)表示x的约数个数,让你求(l,r<=10^12,r-l<=10^6,k<=10^7) #include<cstdio> using namespace std; ...

  9. hdu-1492 The number of divisors(约数) about Humble Numbers---因子数公式

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1492 题目大意: 给出一个数,因子只有2 3 5 7,求这个数的因子个数 解题思路: 直接求出指数即 ...

随机推荐

  1. (四)mybatis之mybatis初了解

    前言:终于到mybatis啦!   Mybatis 前文有提到,Hibernate采用的是全表映射的方式,而这方式恰恰使得性能变得较差(https://www.cnblogs.com/NYfor201 ...

  2. maven打包错误:No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

    [INFO] Scanning for projects...[INFO]                                                                ...

  3. RMQ求区间最大最小值

    #include<iostream> #include<cmath> #include<cstdio> #define N 50005 using namespac ...

  4. 一个小笔记(5):A*算法

    A-Star算法是一种静态路网中求解最短路径最有效的直接搜索方法其实百科有 http://baike.baidu.com/link?url=CvmkWQIAmztYgMq3Nk1WyWkDiC0koV ...

  5. 洛谷 P3958 奶酪

    谨以此题来纪念我爆炸的NOIp2017 这个题虽然很多人说是并查集,但是搜索也是毫无压力的,考场搜索细节写挂,爆了个不上不下的80分.今天无意看到这道题,终于AC 首先这道题要考虑一下精度问题,虽然出 ...

  6. shell脚本,awk 根据文件某列去重并且统计该列频次。

    a文件为 a a a s s d .怎么把a文件变为 a s d .怎么把a文件变为 a a a s s d 解题方法如下: 解题思路 [root@localhost study]# awk 'NR= ...

  7. axure笔记--变量值在页面之间的传递

    fx     先给局部变量赋值,再添加到上面,即给全局变量赋值. 实现页面跳转: 1.打开链接,选择要跳转的下个页面---确定 2.打开那个下一个跳转的页面,要得到上个页面的值,需要到页面交互---页 ...

  8. VC++中char和TCHAR之间转换

    char:计算机编程语言(c.c++.java等)中可容纳单个字符的一种基本数据类型. TCHAR:为了满足Unicode编码,对char的扩展,即_T(“str”)表示TCHAR类型 C++支持两种 ...

  9. Perl学习之四:语句(续)

    循环控制:1.last 退出标签的语句块2.next 3.redo不推荐,循环次数不可控 4.goto不推荐.***************************************标签: 先 ...

  10. linux系统,python3.7环境安装talib过程

    获取源码wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz 解压进入目录tar -zxvf ta-lib-0. ...