UVA10325:The Lottery (容斥)
来源:互联网 发布:淘宝店注册公司 编辑:程序博客网 时间:2024/06/05 09:25
题意:给出N和M个数,要求1~N里面有多少个数,其不能被这M个数任意一个整除。
思路:简单容斥,使用队列数组优化。
# include <iostream># include <cstring># include <cstdlib># include <cstdio># define ll long longusing namespace std;ll n, m, a[100000];ll gcd(ll a, ll b){ return b==0?a:gcd(b, a%b);}ll lcm(ll a, ll b){ return a/gcd(a, b)*b;}ll fun(){ int t, k = 16; ll sum=0; a[k++] = -1; for(int i=0; i<m; ++i) { t = k; for(int j=16; j<t; ++j) a[k++] = lcm(a[i], abs(a[j]))*-1*(a[j]<0?-1:1); } for(int i=17; i<k; ++i) sum += n/a[i]; return sum;}int main(){ while(~scanf("%lld%lld",&n,&m)) { for(int i=0; i<m; ++i) scanf("%lld",&a[i]); printf("%lld\n",n-fun()); } return 0;}
0 0
- UVA10325 The Lottery(容斥原理)
- UVA10325:The Lottery (容斥)
- UVA10325--- The Lottery (容斥)
- UVA10325--- The Lottery (容斥)
- UVa10325 - The Lottery(容斥原理)
- UVa10325 - The Lottery(容斥+最小公倍数)
- 【UVA10325】The Lottery——简单容斥定理
- UVA 10325 - The Lottery ( 容斥 )
- UVA10325(容斥定理)
- 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 容斥原理
- The Lottery uva+容斥原理+求最小公倍数(多个数)
- UVA 10325 The Lottery (组合数学,容斥原理,二进制枚举)
- 今日编程所思
- HDU
- 归并排序
- Luogu-P3372 (Lazy_tag 线段树模板)
- poj The Unique MST 次小生成树(入门级)
- UVA10325:The Lottery (容斥)
- light oj 1245 1245
- 阿里的笔试,正则表达式
- 简单Web项目 struts + hibernate
- 树的遍历专讲(知二求一)
- LeetCoder 6. ZigZag Conversion
- 算法训练 一元三次方程求解 二分
- ADO.NET 快速入门(一):ADO.NET 概述
- ALGO137——Lift and Throw