UVA 10325 - The Lottery(容斥)】的更多相关文章

以前做过的一个题,忘记/gcd了,看来需要把以前的东西看一下啊. #include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include <algorithm> using namespace std; #define LL long long ],flag[]; LL gcd(LL a,LL b) { ?a:gcd(b,a%b); } int main…
UVA.10325 The Lottery (组合数学 容斥原理) 题意分析 首先给出一个数n,然后给出m个数字(m<=15),在[1-n]之间,依次删除给出m个数字的倍数,求最后在[1-n]之间还剩下多少个数字(包括1和n),已知m个数字中不会包含1(否则全部都被刷掉了). 前置技能 1. 给出数字s,在[1-n]之间,s的倍数有n/s个. 2. 给出数字s1,和s2,在[1-n]之间,既是s1的倍数,又是s2的倍数,有n/lcm(s1,s2)个. 3. 给出数字s1,s2--sk(共k个数字…
10325 - The Lottery The Sports Association of Bangladesh is in great problem with their latest lottery ‘Jodi laiga Jai’. Thereare so many participants this time that they cannot manage all the numbers. In an urgent meeting theyhave decided that they…
The Sports Association of Bangladesh is in great problem with their latest lottery `Jodi laiga Jai'. Thereare so many participants this time that they cannot manage all the numbers. In an urgent meeting theyhave decided that they will ignore some num…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2906 容斥原理,从反面去想.统计边界上都没有石子的情况.这时候就要用到容斥原理了. 代码如下: #include <iostream> #include <algorithm> #include <cstring> #include <cstdio&…
In most professional sporting events, cheerleaders play a major role in entertaining the spectators. Theirroles are substantial during breaks and prior to start of play. The world cup soccer is no exception.Usually the cheerleaders form a group and p…
首先推荐一篇介绍容斥原理很好的博客http://www.cppblog.com/vici/archive/2011/09/05/155103.html 题意:求1~n中不能被给定m个数中任意一个数整除的数的个数. 思路:n-sum(能被整除的个数) 明显用容斥原理:如10 - 能被2整除的数的个数 - 能被3整除的数的个数 + 能被6整除的数的个数 20-能被2整除的数的个数-能被4整除的数的个数+能被4整除的数的个数(2,4的最小公倍数) 加上或减去的是(n/某种组合的最小公倍数) #incl…
/** 题目:Trees in a Wood. UVA 10214 链接:https://vjudge.net/problem/UVA-10214 题意:给定a,b求 |x|<=a, |y|<=b这个范围内的所有整点不包括原点都种一棵树.求出你站在原点向四周看到的树的数量/总的树的数量的值. 思路: 坐标轴上结果为4,其他四个象限和第一个象限看到的数量一样.所以求出x在[1,a]和y在[1,b]的x/y互质对数即可. 由于a比较小,所以枚举x,然后求每一个x与[1,b]的互质对数. 方法: 1…
  题意:规定每次跳的单位 a1, a2, a3 …… , an, M,次数可以为b1, b2, b3 …… bn, bn + 1, 正好表示往左,负号表示往右, 求能否调到左边一位,即 a1* b1+ a2 * b2 + a3 * b3 + …… + m * (bn + 1) = 1; 根据欧几里得,则a1, a2 a3 …… an, m 最大公约数为1,m已知且a1, a2, a3 …… an 均小于等于m, 一共有m ^ n可能, 将m 唯一分解之后, 假设m = 2 * 3 * 5, 则…
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #define LL long long using namespace std; ; ; LL Factor[],cnt,n,m,tot,Rev,Kase,Prime[Maxn]; bool vis[Maxn]; inline LL Quick_Pow(LL x,LL y) { LL Ret=; whi…