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,求这个数的因子个数 解题思路: 直接求出指数即 ...
随机推荐
- C#反射调用小DEMO
程序集的源代码: namespace DesignMode { class IOCTest { public void TestO() { Console.WriteLine("O方法&qu ...
- IOS7.1 企业应用 证书无效 已解决
http://www.cocoachina.com/bbs/read.php?tid=194213&keyword=7.1 关于IOS7.1企业版发布后,用户通过SARAFI浏览器安装无效的解 ...
- iOS5 and iOS6都只支持横屏的方法
If your app uses a UINavigationController, then you should subclass it and set the class in IB. You ...
- maven项目jsp无法识别jstl的解决办法
EL表达式无效是因为maven项目的jsp不识别jstl,只要在web-APP 标签中引入命名空间 xmlns="http://xmlns.jcp.org/xml/ns/javaee&quo ...
- Airbnb:别抵制我,宝宝要过 10 岁生日
今日导读 喜欢旅游的你,一定听说或使用过 airbnb(爱彼迎),在出发前打开它,总是能通过它开始一段奇妙的旅行.可是最近,就在这个打着“共享家”概念的服务型网站正迎来十周年之际,它却遭到了很多国家的 ...
- BCB:AnsiString和String的区别
AnsiString和String的区别.使用 本文转自:http://www.bianceng.cn/c/index.htm 16.C/C++语言在CB中的一些特定用法 2)AnsiString是从 ...
- VC-基础:MFC单文档程序架构解析
MFC单文档程序架构解析 这里我以科院杨老师的单文档程序来分析一下MFC单文档的程序架构,纯属个人见解,不当之处烦请指教! 首先我们了解到的是 图(一) theApp 是唯一一个在程序形成的时候就存在 ...
- 题解 CF440A 【Forgotten Episode】
博客阅读更好 虽然这道题是紫题,但实际难度应该是橙题吧 首先,看到标签…… 紫题?但题目也太…… 这道题教会我们不要看标签 好了,废话少说,看到楼下许多大佬都用了数组,但我觉得可以不用 为什么? 我也 ...
- java在线聊天项目1.3版 ——设计好友列表框功能
设计好友列表框功能,思路—— 1.当客户端成功登陆后,则客户端把成功登陆信息发送给服务端, 2.由服务端将接收到来自各个成功登陆的客户端的用户信息添加进好友列表, 3.每当有成功登陆的用户就向各个客户 ...
- css去除链接 input 虚框
/* css去掉虚框 */ :focus{-webkit-outline-style:none;-moz-outline-style:none;-ms-outline-style:none;-o-ou ...