Nk 1430 Divisors(因子数与质因数)
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(因子数与质因数)的更多相关文章
- HDU6069:Counting Divisors(因子数统计|区间筛)
题意 计算\(\sum_{i=l}^kd(i^k)(d_i代表i的因子数)\) 分析 比赛搞了3个小时都没搞出来,有两个思维上的trick 1.要先遍历素数,再遍历[L,R],而不是枚举每个数,然后对 ...
- Nk 1430 Fibonacci(二分矩阵乘幂)
AC代码: #include<iostream> using namespace std; ][]; ][]; ][]; ][]; void binary(int n) { int i,j ...
- 从“n!末尾有多少个0”谈起
在学习循环控制结构的时候,我们经常会看到这样一道例题或习题.问n!末尾有多少个0?POJ 1401就是这样的一道题. [例1]Factorial (POJ 1401). Description The ...
- Day 2 T1
题目描述 组合数表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三个物品中选择两个物品可以有(1,2),(1,3),(2,3)这三种选择方法.根据组合数的定 义,我们可以给出计算 ...
- 2017ACM暑期多校联合训练 - Team 4 1003 HDU 6069 Counting Divisors (区间素数筛选+因子数)
题目链接 Problem Description In mathematics, the function d(n) denotes the number of divisors of positiv ...
- HDU 6069 Counting Divisors(唯一分解定理+因子数)
http://acm.hdu.edu.cn/showproblem.php?pid=6069 题意: 思路: 根据唯一分解定理,$n={a_{1}}^{p1}*{a2_{}}^{p2}...*{a_{ ...
- A - Divisors POJ - 2992 (组合数C的因子数)数学—大数
题意:就是求组合数C的因子的个数! 先说一下自己THL的算法,先把组合数求出来,然后将这个大数分解,得到各个素数的个数,再利用公式!用最快的大数分解算法 分析一下时间复杂度! n1/4但是分析一下 ...
- 【线性筛】【质因数分解】【约数个数定理】hdu6069 Counting Divisors
d(x)表示x的约数个数,让你求(l,r<=10^12,r-l<=10^6,k<=10^7) #include<cstdio> using namespace std; ...
- hdu-1492 The number of divisors(约数) about Humble Numbers---因子数公式
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1492 题目大意: 给出一个数,因子只有2 3 5 7,求这个数的因子个数 解题思路: 直接求出指数即 ...
随机推荐
- codevs 1553 互斥的数
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 有这样的一个集合,集合中的元素个数由给定的N决定,集合的元素为N个不同的正整数, ...
- javascript基本类型和引用类型,作用域和内存问题
基本类型(null.undefined.boolean.number.string)和引用类型(Object 对象) 1 基本类型:只能不存一个值,一种类型:从一个变量向另一个变量复制基本类型的值, ...
- delphi win7 and high path
Close DelphiLocate bordbk120N.dll (C:\Program Files (x86)\CodeGear\RAD Studio\6.0\bin)Make a backup ...
- Memcache查看列出所有key方法
Memcached查看列出所有key方法 测试的过程中,发现Memcached没有一个比较简单的方法可以直接象redis那样keys *列出所有的Session key,并根据key get对应的se ...
- 将Xcode的本地代码push到github仓库上
1.首先,你得有一个github账号,如果没有的话就去注册一个,通过下面图片的方式创建一个github仓库. 2.创建仓库后填写相关的信息,比如说仓库名等. 3.在xcode上进行设置,添加远程git ...
- Fortran学习笔记6(函数、子程序)
子程序Subroutine 自定义函数Function 全局变量COMMON BLOCK DATA 程序代码中,常常会在不同的地方重复用到某一功能和重复某一代码,这个时候就要使用函数.函数包括内嵌函数 ...
- 对uboot中CFG_和CONFIG_的理解
CONFIG_用于选择CPU SOC 板子的类型,系统时钟,设备驱动driver驱动等 CFG_用于设置malloc缓冲池的大小,偏移地址部分的定义,uboot的提示符,uboot的加载地址,fl ...
- 快速入门Pandas
教你十分钟学会使用pandas. pandas是python数据分析的一个最重要的工具. 基本使用 # 一般以pd作为pandas的缩写 import pandas as pd # 读取文件 df = ...
- Python中摘要算法MD5,SHA1讲解
摘要算法又称哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一个长度固定的数据串(通常用16进制的字符串表示).摘要算法就是通过摘要函数f()对任意长度的数据data计算出固定长度的摘要di ...
- DocView mode 0 -- 介绍
DocView mode,可作为主模式也可以作为minor mode,可以用来阅读DVI(ps后缀),PDF,OpenDocument(libreoffice文档),微软的doc.支持截取 ...