Ural 1091 Tmutarakan Exams (水题 容斥+ 莫比乌斯反演)
来源:互联网 发布:淘宝店铺资质25000元 编辑:程序博客网 时间:2024/05/15 23:53
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 numberS. The numbersK and 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 wereK=25 andS=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 exceedingS, 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 numbersK andS (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
Tags: number theory
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1091
题目大意:从1-s中选k个不同的数组成一个集合,要求它们的最大公约数大于1,问有多少个这样的集合,大于10000输出10000
题目分析:k和s都那么小,直接从2开始枚举最大公约数,i的倍数有s / i个,从中选k个为c[s / i][k],再用莫比乌斯函数容斥一下
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1091
题目大意:从1-s中选k个不同的数组成一个集合,要求它们的最大公约数大于1,问有多少个这样的集合,大于10000输出10000
题目分析:k和s都那么小,直接从2开始枚举最大公约数,i的倍数有s / i个,从中选k个为c[s / i][k],再用莫比乌斯函数容斥一下
#include <cstdio>#define ll long longint const MAX = 55;ll c[30][30];int mob[MAX], p[MAX];bool noprime[MAX];void Init(){ for(int i = 0; i <= 25; i++) c[i][0] = 1; for(int i = 1; i <= 25; i++) for(int j = 1; j <= 25; j++) c[i][j] = c[i - 1][j - 1] + c[i - 1][j];}void Mobius(){ int pnum = 0; mob[1] = 1; for(int i = 2; i < MAX; i++) { if(!noprime[i]) { p[pnum ++] = i; mob[i] = -1; } for(int j = 0; j < pnum && i * p[j] < MAX; j++) { noprime[i * p[j]] = true; if(i % p[j] == 0) { mob[i * p[j]] = 0; break; } mob[i * p[j]] = -mob[i]; } }}int main(){ Init(); Mobius(); int k, s; ll ans = 0; scanf("%d %d", &k, &s); for(int i = 2; i <= s; i++) for(int j = i; j <= s; j += i) ans += (ll) c[s / j][k] * mob[j / i]; if(ans > 10000) ans = 10000; printf("%I64d\n", ans);}
0 0
- Ural 1091 Tmutarakan Exams (水题 容斥+ 莫比乌斯反演)
- Ural 1091. Tmutarakan Exams (莫比乌斯反演)
- URAL1091: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 (DP或容斥)
- 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
- (组合数学3.3.2.1)URAL 1091. Tmutarakan Exams(容斥定理)
- Tmutarakan Exams 简单的容斥定理
- js 判断两个标准时间是不是同一周
- codeforces round 319 div2 题解
- Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE
- 利用RecyclerView实现瀑布流效果
- 深度学习关键词之—过拟合
- Ural 1091 Tmutarakan Exams (水题 容斥+ 莫比乌斯反演)
- linux中配置phpcms v9 中的sphinx
- Inventor API代码性能优化 - 2
- 按序取出一列表格数据
- iOS时间那点事
- 微信端分享接口
- Qt自带的软件安装包制作工具
- 数据结构之简单四则运算表达式求值8-(栈的实现)
- 值得推荐的C/C++框架和库