Divisors POJ
来源:互联网 发布:党规党纪面前知敬畏守 编辑:程序博客网 时间:2024/06/05 22:49
题目链接
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 2 63 - 1.
Sample Input
5 16 310 4
Sample Output
2616
题意:
求组合数的因子个数.
思路:
大概就是将组合数写成阶乘的形式, 然后统计每个质数因子的个数即可.
代价:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;typedef long long LL;const int maxn = 500;int pri[maxn];int a[maxn];int b[maxn];bool vis[maxn];int num;void prime(){ num = 0; memset(vis, false, sizeof(vis)); for(int i = 2; i < maxn; ++i){ if (!vis[i]) pri[++num] = i; for(int j = 1; j <= num && i * pri[j] < maxn; ++j){ vis[ i* pri[j]] = true; if (i % pri[j] == 0) break; } }}int solve(int n, int t){ int ans = 0; int x = t; while(t <= n){ ans += n / t; t *= x; }return ans;}int main(){ //ios::sync_with_stdio(false); int n, m; prime(); while(scanf("%d %d", &m, &n) != EOF){ // if(n > m / 2) n = m - n; LL ans = 1; for(int i = 1; i <= num && pri[i] <= m; ++i) ans *=(solve(m, pri[i]) - solve(n, pri[i]) - solve(m - n, pri[i]) + 1); printf("%lld\n",ans); }return 0;}
阅读全文
0 0
- Divisors POJ
- 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 整数分解
- POJ 2992 Divisors (因子个数)
- POJ 2992 Divisors (因子个数)
- Divisors
- Divisors
- Divisors
- Codeforces 454D Little Pony and Harmony Chest【思维+状压Dp+记录路径】好题!
- Java类初始化顺序
- Proving Equivalences HDU
- Pixhawk飞行模式的讨论
- 集合类
- Divisors POJ
- HDOJ2054(大数处理)
- C++常见面试题(一)C/C++区别 const用法
- 文件操作——File
- 【网页--HTML使用教程】
- Java SE8 Lambda 基础入门---lambda表达式的类型是什么
- H5 表格的结构图
- 【NOIP2015】 跳石头
- 图片在水平上居中的原理