Ural 1091. Tmutarakan Exams 排列组合+容斥原理+质因数分解
来源:互联网 发布:卡五星麻将app源码 编辑:程序博客网 时间:2024/05/22 12:45
1091. Tmutarakan Exams
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
University of New Tmutarakan trains the first-class specialists in mental arithmetic. To enter the University you should master arithmetic perfectly. One of the entrance exams at the Divisibility Department is the following. Examinees are asked to find K different numbers that have a common divisor greater than 1. All numbers in each set should not exceed a given number S. The numbers Kand S are announced at the beginning of the exam. To exclude copying (the Department is the most prestigious in the town!) each set of numbers is credited only once (to the person who submitted it first).
Last year these numbers were K=25 and S=49 and, unfortunately, nobody passed the exam. Moreover, it was proved later by the best minds of the Department that there do not exist sets of numbers with the required properties. To avoid embarrassment this year, the dean asked for your help. You should find the number of sets of K different numbers, each of the numbers not exceeding S, which have a common divisor greater than 1. Of course, the number of such sets equals the maximal possible number of new students of the Department.
Input
The input contains numbers K and S (2 ≤ K ≤ S ≤ 50).
Output
You should output the maximal possible number of the Department's new students if this number does not exceed 10000 which is the maximal capacity of the Department, otherwise you should output 10000.
Sample
3 10
11
Problem Author: Stanislav Vasilyev
Problem Source: USU Open Collegiate Programming Contest March'2001 Senior Session
Problem Source: USU Open Collegiate Programming Contest March'2001 Senior Session
要求找出K个不同的数字使他们有一个大于1的公约数。所有的数字都不能大于一个指定的数字S。
枚举素数和两个素数的乘积,运用容斥原理判断.
#include <iostream>#include <cstring>using namespace std;int k, s, ans, num, cnt;long long C[55][55];int prime[9] = {2,3,5,7,11,13,17,19,23};void calc(){ memset(C, 0, sizeof(C)); C[1][0] = 1; C[1][1] = 1; for (int i = 2; i <= 50; ++ i) { C[i][0] = 1; for (int j = 1; j <= i; ++ j) C[i][j] = C[i-1][j-1] + C[i-1][j]; }}int main(){ calc(); while (cin >> k >> s) { ans = 0; cnt = 9; for (int i = 0; i < 9; ++ i) { num = s / prime[i]; if (num < k) { cnt = i; break; } else ans += C[num][k]; } for (int i = 0; i < cnt; ++ i) { for (int j = i+1; j < cnt; ++ j) { num = s / (prime[i]*prime[j]); if (num < k) break; else ans -= C[num][k]; } } if (ans > 10000) ans = 10000; cout << ans << endl; }}
- Ural 1091. Tmutarakan Exams 排列组合+容斥原理+质因数分解
- Ural 1091. Tmutarakan Exams 容斥原理
- Ural 1091 Tmutarakan Exams [容斥原理]
- Ural 1091 Tmutarakan Exams【容斥原理】
- URAL 1091 Tmutarakan Exams(容斥原理)
- ural 1091. Tmutarakan Exams(容斥)
- URAL 1091. Tmutarakan Exams 容斥
- Ural 1091 Tmutarakan Exams 解题报告(容斥原理)
- 【URAL】1091 Tmutarakan Exams (简单容斥原理)
- URAL 1091. Tmutarakan Exams
- URAL1091 Tmutarakan Exams (容斥原理)
- URAL 1091 Tmutarakan Exams (DP或容斥)
- URAL 1091 Tmutarakan Exams 【容斥】【组合数】
- (组合数学3.3.2.1)URAL 1091. Tmutarakan Exams(容斥定理)
- URAL 1091 Tmutarakan Exams
- Ural 1091 Tmutarakan Exams (水题 容斥+ 莫比乌斯反演)
- Tmutarakan Exams 简单的容斥定理
- 容斥原理+质因数分解+组合数学
- A+B Problem新解
- C++文件流_矩阵相乘
- shell脚本学习-为什么使用 shell 编程
- scrollTo、scrollBy、getScrollX、getScrollY这4个方法的含义
- thunderbird邮箱备份方法
- Ural 1091. Tmutarakan Exams 排列组合+容斥原理+质因数分解
- 中缀表达式转后缀表达式的方法
- 怎样选择适合自己个人博客的虚拟主机
- Spring集成Quartz定时任务框架介绍和Cron表达式详解
- 计算器
- discuz big5 移动版发布帖子,丢失文字的解决方法
- fzu训练赛14 I - Prime Substring
- 通过StackManager对Android应用的Activity进行自己管理的工具类
- 手游开发之惑:好玩不过单机,厂商却独爱网游