UVA 10325 - The Lottery(容斥)
以前做过的一个题,忘记/gcd了,看来需要把以前的东西看一下啊。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define LL long long
int p[],flag[];
LL gcd(LL a,LL b)
{
return b == ?a:gcd(b,a%b);
}
int main()
{
int n,i,j,ans,num,m;
LL temp;
while(scanf("%d%d",&n,&m)!=EOF)
{
ans = ;
memset(flag,,sizeof(flag));
for(i = ;i < m;i ++)
scanf("%d",&p[i]);
sort(p,p+m);
num = ;
for(i = ;i < m;i ++)
{
if(!flag[i])
p[num++] = p[i];
for(j = i+;j < m;j ++)
{
if(p[j]%p[i] == )
flag[j] = ;
}
}
m = num;
for(i = ;i < (<<m);i ++)
{
temp = ;
num = ;
for(j = ;j < m;j ++)
{
if(i&(<<j))
{
temp = temp*p[j]/gcd(temp,p[j]);
num ++;
}
}
if(num%)
ans += n/temp;
else
ans -= n/temp;
}
printf("%d\n",n-ans);
}
return ;
}
UVA 10325 - The Lottery(容斥)的更多相关文章
- UVA.10325 The Lottery (组合数学 容斥原理 二进制枚举)
UVA.10325 The Lottery (组合数学 容斥原理) 题意分析 首先给出一个数n,然后给出m个数字(m<=15),在[1-n]之间,依次删除给出m个数字的倍数,求最后在[1-n]之 ...
- uva - The Lottery(容斥,好题)
10325 - The Lottery The Sports Association of Bangladesh is in great problem with their latest lotte ...
- UVA 10325 The Lottery( 容斥原理)
The Sports Association of Bangladesh is in great problem with their latest lottery `Jodi laiga Jai'. ...
- uva 11806 Cheerleaders (容斥)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- UVA 11806 Cheerleaders dp+容斥
In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...
- 容斥原理——uva 10325 The Lottery
首先推荐一篇介绍容斥原理很好的博客http://www.cppblog.com/vici/archive/2011/09/05/155103.html 题意:求1~n中不能被给定m个数中任意一个数整除 ...
- Trees in a Wood. UVA 10214 欧拉函数或者容斥定理 给定a,b求 |x|<=a, |y|<=b这个范围内的所有整点不包括原点都种一棵树。求出你站在原点向四周看到的树的数量/总的树的数量的值。
/** 题目:Trees in a Wood. UVA 10214 链接:https://vjudge.net/problem/UVA-10214 题意:给定a,b求 |x|<=a, |y|&l ...
- POJ1091跳蚤(容斥 + 唯一分解 + 快速幂)
题意:规定每次跳的单位 a1, a2, a3 …… , an, M,次数可以为b1, b2, b3 …… bn, bn + 1, 正好表示往左,负号表示往右, 求能否调到左边一位,即 a1* b1 ...
- HDU 4059 容斥初步练习
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...
随机推荐
- Linux 千万不要执行的10个命令
1. rm -rf 命令 rm -rf命令是删除文件夹及其内容最快的方式之一.仅仅一丁点的敲错或无知都可能导致不可恢复的系统崩坏.下列是一些rm 命令的选项. rm 命令在Linux下通常用来删除文件 ...
- Python爬虫经验
有时候读取同一个url,服务器可能会返回不同的response,并不是爬虫程序代码的问题,而是服务器的问题,初次试验request时,最好 把response文本保存在一个txt文件当中,以便后续的比 ...
- sharepoint bcs (bussiness connectivity services)
sharepoint bcs 在2010 版本中是提供2010 与外部数据连接的. BCS全名Business Connectivity Services,可以把它看成SharePoint 2007 ...
- iterator与const_iterator及const iterator区别
如果你传递过来一个const类型的容器,那么只能用const_iterator来遍历. C++ Code 12345 void Method(const vector<int> v ...
- iOS 使用Storyboard 和 xib时的一些知识
以前不太使用xib和storyboard进行布局,后来在工作中参与到了一个项目的维护工作,那个项目就是使用stroyboard的,再加上xcode5对stroyboard的大力支持,就在这里对于使用s ...
- c# 获取屏幕DPI
方法一:用ManagementClass来获取.需要引入System.Management.dll; using (ManagementClass mc = new ManagementClass(& ...
- codeforces 471B. MUH and Important Things 解题报告
题目链接:http://codeforces.com/problemset/problem/471/B 题目意思:有 n 个 tasks,编号依次为 1 - n,每个 task 都有一定的难度值来评估 ...
- UESTC 1215 (思维题 旋转)
Secrete Master Plan Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Othe ...
- ios获取一个文件夹下的文件(夹)列表
NSArray* ary=[[NSFileManager defaultManager] contentsOfDirectoryAtPath:[[NSBundle mainBundle] pathFo ...
- ubuntu使用root账户登录
1.先设定一个root的密码 sudo passwd root 2.编辑lightdm.conf sudo gedit /etc/lightdm/lightdm.conf 最后一行添加 greeter ...