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,求这个数的因子个数 解题思路: 直接求出指数即 ...
随机推荐
- python 基础网络编程1
python 基础网络编程1 Source code: Lib/socketserver.py lib的主目录下有一个sockserver.py文件, 里面是python基本的网络编程模型 共有一个b ...
- XDU——受教了
存在的问题还是很多的 GG 突然觉得刷题的目的并不是追求A.我们应该在那个过程中提高代码能力和建立模型解题能力 会的算法会巧妙应用才是王道 吐槽自己两句,写高数了
- core 下使用 autofac
依赖注入小伙伴们比较常了,这里只说core 下autofac依赖注入的使用 ,不多费话,直接代码. 在 Startup.cs里 public void ConfigureServices(IServi ...
- java B转换KB MB GB TB PB EB ZB
public static String readableFileSize(long size) { if (size <= 0) { return "0"; } final ...
- 题解 P5082 【成绩】
随机跳题跳到了这一题,一看是个红题,本蒟蒻就 艰难地思考起来 高兴地写起来 这题实在不能用数组,用了数组就RE 一开始就卡在这上面了 说实话,这道题真的 很难 不算很难,只要照着公式往上面套就行了 废 ...
- ubuntu frp 自编译。本文不能按顺序来 请自己理解
go run:go run 编译并直接运行程序,它会产生一个临时文件(但不会生成 .exe 文件),直接在命令行输出程序执行结果,方便用户调试. go build:go build 用于测试编译包,主 ...
- vue建项目并使用
今天来回顾下vue项目的建立和使用,好久不用感觉不会用了. 下面两个都要全局安装 首先安装git,地址 https://gitforwindows.org/ 安装node, 地址 https://n ...
- 长链剖分优化dp三例题
首先,重链剖分我们有所认识,在dsu on tree和数据结构维护链时我们都用过他的性质. 在这里,我们要介绍一种新的剖分方式,我们求出这个点到子树中的最长链长,这个链长最终从哪个儿子更新而来,那个儿 ...
- Safari不能保存session的处理方法
在vue单页应用项目中,safari浏览器验证码登陆提示'验证码过期'或者验证码校验不通过的问题 原因:验证码存储在了session里,接着验证时又发起了一次会话,因为Safari不保存cookie, ...
- Django 模版语法 三
使用自定义simple_tag 在 app01 下面创建 templatetags 文件夹,在创建 my_tag.py 文件,内容如下: from django import template fro ...