POJ 2992 Divisors(求组合数因子个数)
来源:互联网 发布:广告算法工程师招聘 编辑:程序博客网 时间:2024/05/21 14:44
Divisors
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 12048 Accepted: 3594
Description
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 16 310 4
Sample Output
2616
Source
CTU Open 2005
[Submit] [Go Back] [Status] [Discuss]
Home Page Go Back To top
题意:求C(n,k)的因子个数。
题解:C(n,k)=n!/k!/(n-k)!,直接将所有阶乘的数分解出所有素因数然后统计一下
然后套用因数个数公式就好 (p1+1)*(p2+1)*(p3+1)*...*(pn+1)
题目很简单,然而卡时间,500*50*50都卡??
好吧,预处理一下就OK了。。。。。
定义dp[i][j]:表示i的阶乘里有几个素数j。
#include<set> #include<map> #include<stack> #include<queue> #include<vector> #include<string> #include<time.h> #include<math.h> #include<stdio.h> #include<iostream> #include<string.h> #include<stdlib.h> #include<algorithm> #include<functional> using namespace std; #define ll long long #define inf 1000000000 #define mod 1000000007 #define maxn 50500 #define lowbit(x) (x&-x) #define eps 1e-9 ll a[505]={1,1},b[500];ll dp[450][450],cnt;void init(){ll i,j;for(i=2;i<=432;i++){if(a[i])continue;b[++cnt]=i;for(j=i*i;j<=432;j+=i)a[j]=1;}for(i=2;i<=432;i++){for(j=1;b[j]<=i && j<=cnt;j++){ll tmp=i,res=0;while(tmp)tmp/=b[j],res+=tmp;dp[i][b[j]]=res;}}}int main(void){init();ll i,x,y;while(scanf("%lld%lld",&x,&y)!=EOF){ll ans=1;for(i=1;b[i]<=x && i<=cnt;i++){ll tmp=dp[x][b[i]]-dp[y][b[i]]-dp[x-y][b[i]];ans=ans*(tmp+1);}printf("%lld\n",ans);}return 0;}
阅读全文
0 0
- POJ 2992 Divisors(求组合数因子个数)
- poj 2992 Divisors(求组合数的因子个数)
- POJ 2992 Divisors 求组合数因子个数
- POJ 2992 : Divisors - 求组合数的因子个数
- POJ 2992-Divisors(求组合数质因子的个数)
- POJ 题目2992 Divisors(组合数因子个数)
- poj 2992 Divisors(求因子个数)
- POJ 2992 Divisors 求组合数的约数个数
- POJ 2992 Divisors (因子个数)
- POJ 2992 Divisors (因子个数)
- POJ 2992 Divisors 求一个数的因数的个数
- POJ 2992 Divisors (快速求阶乘的素因子)
- codeforces 665F. Four Divisors(求n以内因子数是4的数的个数)
- poj 2992 Divisors n!的因子个数的计算
- POJ 2992 Divisors(欧拉素筛+组合数分解)
- uva 294 Divisors 求因子个数
- POJ-2292(求约数个数)(Divisors)
- POJ2992 Divisors【因子个数】
- QTcpSocket 通讯 ( 服务器、客户端、封包、解包 )
- java开发/10.1-10.3/邓聪
- 微信公众号title替换
- Java编程思想读书笔记——持有对象
- IntelliJ 添加JRebel 实现 Tomcat热部署
- POJ 2992 Divisors(求组合数因子个数)
- C++判断出栈顺序
- C++构造函数简述
- 一个合格的程序员应该读过哪些书
- javaWeb之jsp转化servlet
- 众多回文问题
- WinMIPS64下实现冒泡排序(函数调用)
- anhularjs-路由。关于嵌入html页面
- Python3错误和异常