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> ...
随机推荐
- LSB 简介
前 Linux 的发行版非常繁多,为了促进 Linux 不同发行版间的兼容性,LSB(Linux Standards Base)开发了一系列标准,使各种软件可以很好地在兼容 LSB 标准的系统上运行, ...
- MogileFS 的介绍(MogileFS 系列1)[分布式文件系统]
MogileFS 是一个开源的分布式文件系统,用于组建分布式文件集群,由 LiveJournal 旗下 Danga Interactive 公司开发,Danga 团队开发了包括 Memcached.M ...
- Java for LeetCode 173 Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the ro ...
- 中石油-高精度除法-java版
问题 G: [高精度]高精度数除以低精度数I 时间限制: 1 Sec 内存限制: 512 MB提交: 19 解决: 15[提交][状态][讨论版] 题目描述 修罗王聚集了庞大的暗元素以施展隐匿魔法 ...
- BestCoder9 1003 Revenge of kNN(hdu 4995) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4995 题目意思:在一个一维坐标轴上,给出位置 xi 和值 vi,对于 M 次询问,每次询问给出inde ...
- Java删除文件夹和文件
转载自:http://blog.163.com/wu_huiqiang@126/blog/static/3718162320091022103144516/ 以前在javaeye看到过关于Java操作 ...
- 【读书笔记】读《JavaScript高级程序设计-第2版》 - 非函数部分
章节列表: 第08章:BOM 第09章:客户端检测 第10章:DOM 第11章:DOM2和DOM3 第12章:事件 第13章:表单脚本 第14章:错误处理与调试 第17章:Ajax和JSON第20章: ...
- java equals 和 "==" 比较
java中的数据类型,可分为两类: 1.基本数据类型,也称原始数据类型.byte,short,char,int,long,float,double,boolean 他们之间的比较,应用双等号(== ...
- CI框架获取post和get参数_CodeIgniter心得
请参考:CI文档的输入类部分: $this->input->post() $this->input->get() ------------------------------- ...
- 使用ASP.NET Web API自带的类库实现对CORS的支持(在开发中使用这种方式)(转载)
在<通过扩展让ASP.NET Web API支持W3C的CORS规范>中我们通过自定义的HttpMessageHandler为ASP.NET Web API赋予了跨域资源共享的能力,具体来 ...