UVA 10325 The Lottery
来源:互联网 发布:fm2017 数据分析师 编辑:程序博客网 时间:2024/05/01 19:58
容斥原理求集合并集.
这里的集合就是给出的M个数,每个数的倍数(小于等于N)就是一个集合.
先求出最小公倍数,然后 N/最小公倍数 就可以得出每个子集的元素数量.
#include <iostream>#include <cstdio>using namespace std;long long gcd(long long a, long long b){return b == 0 ? a : gcd(b, a % b);}long long lcm(long long a, long long b){return a / gcd(a, b) * b;}long long N, M, sel[16];int main(){while (scanf("%lld%lld", &N, &M) == 2){long long ans = N;long long uni = 0;for (int i = 0; i < M; ++i){scanf("%lld", &sel[i]);}for (long long i = 0; i < (1 << M); ++i){long long cnt = 0, lcmn = 1;for (long long j = 0; j < M; ++j){if ((1 << j) & i){cnt++;lcmn = lcm(lcmn, sel[j]);}}if(cnt == 0)continue;if(cnt & 1){uni += N / lcmn;}else{uni -= N / lcmn;}}printf("%d\n", ans - uni);}return 0;}
- UVA 10325 The Lottery
- UVa 10325 - The Lottery
- UVA 10325 - The Lottery ( 容斥 )
- UVa 10325 The Lottery 【容斥】【入门】
- UVa 10325 The Lottery 容斥原理
- uva 10325 The Lottery(组合数学-容斥原理)
- UVA 10325 The Lottery(组合+容斥)
- UVA 10325 The Lottery(容斥原理)
- UVA 10325 The Lottery(容斥原理)
- UVA 10325 The Lottery( 容斥原理)
- uva 10325 The Lottery 枚举子集+容斥原理
- UVA 10325 The Lottery (组合数学,容斥原理,二进制枚举)
- uva 10325 The Lottery (容斥原理)dfs枚举 或二进制枚举
- UVA.10325 The Lottery (组合数学 容斥原理 二进制枚举)
- UVA 10325 lottery 容斥原理
- [高斯消元]UVA 12961 Lottery
- The Lottery uva+容斥原理+求最小公倍数(多个数)
- UVA10325--- The Lottery (容斥)
- eclipse 安装maven插件
- 学了.Net能做什么开发 (转)
- 黑马程序员_java代理模式
- Json Parsing Error : JSON.parse: bad control character in string literal错误解决
- .Net应该学什么怎么学(一)
- UVA 10325 The Lottery
- win7 卸载IE10
- GridView里面根据状态代码来更改GridView的底色
- 计算机网络6
- Windows环境下配置Python的环境变量
- 图片延迟加载 jquery
- 黑马程序员--String类
- 性能loadrunner--loadrunner中打印出参数的值
- [ 杂项 ] 网页访问过程!