以前做过的一个题,忘记/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(容斥)的更多相关文章

  1. UVA.10325 The Lottery (组合数学 容斥原理 二进制枚举)

    UVA.10325 The Lottery (组合数学 容斥原理) 题意分析 首先给出一个数n,然后给出m个数字(m<=15),在[1-n]之间,依次删除给出m个数字的倍数,求最后在[1-n]之 ...

  2. uva - The Lottery(容斥,好题)

    10325 - The Lottery The Sports Association of Bangladesh is in great problem with their latest lotte ...

  3. UVA 10325 The Lottery( 容斥原理)

    The Sports Association of Bangladesh is in great problem with their latest lottery `Jodi laiga Jai'. ...

  4. uva 11806 Cheerleaders (容斥)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  5. UVA 11806 Cheerleaders dp+容斥

    In most professional sporting events, cheerleaders play a major role in entertaining the spectators. ...

  6. 容斥原理——uva 10325 The Lottery

    首先推荐一篇介绍容斥原理很好的博客http://www.cppblog.com/vici/archive/2011/09/05/155103.html 题意:求1~n中不能被给定m个数中任意一个数整除 ...

  7. 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 ...

  8. POJ1091跳蚤(容斥 + 唯一分解 + 快速幂)

      题意:规定每次跳的单位 a1, a2, a3 …… , an, M,次数可以为b1, b2, b3 …… bn, bn + 1, 正好表示往左,负号表示往右, 求能否调到左边一位,即 a1* b1 ...

  9. HDU 4059 容斥初步练习

    #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...

随机推荐

  1. Linux LVS Nginx HAProxy 优缺点

    说明:以下内容参考了抚琴煮酒的<构建高可用Linux服务器>第六章内容. 搭建负载均衡高可用环境相对简单,主要是要理解其中原理.此文描述了三种负载均衡器的优缺点,以便在实际的生产应用中,按 ...

  2. 什么是响应式Web设计?怎样进行?

    http://beforweb.com/node/6/page/0/3 开始第一篇.老规矩,先无聊的谈论天气一类的话题.十一长假,天气也终于开始有些秋天的味道,坐在屋里甚至觉得需要热咖啡.话说两年前也 ...

  3. php __set() __get() __isset() __unset()四个方法的应用

    一般来说,总是把类的属性定义为private,这更符合现实的逻辑.但是,对属性的读取 和赋值操作是非常频繁的,因此在PHP5 中,预定义了两个函数“__get()”和“__set()”来获 取和赋值其 ...

  4. 【Python】 Django 怎么实现 联合主键?

    unique_together¶ Options.unique_together¶ Sets of field names that, taken together, must be unique: ...

  5. Flip Game I && II

    Flip Game I Problem Description: You are playing the following Flip Game with your friend: Given a s ...

  6. 动态设置Div坐标

    <style type="text/css"> #main{text-align:center; background-color:#9FF; height:600px ...

  7. msysgit ls 中文显示

    2013年10月17日 14:54:15 安装了新版的msysgit后,在其自带的 git bash 命令行下就可以输入中文汉字了 但是创建了中文名字命名的文件后,再用 ls 命令查询时会出现乱码的情 ...

  8. Java for LeetCode 188 Best Time to Buy and Sell Stock IV【HARD】

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  9. jquery记住密码,记住账号,自动登录

    1.引入jquery库 2.引入jquery.cookie.js库 3.引入操作js jsp如下: $(document).ready(function() { //输入框获得焦点-失去焦点 $(&q ...

  10. [Android Pro] PackageManager#getPackageSizeInfo (hide)

    referce to : http://www.baidufe.com/item/8786bc2e95a042320bef.html 计算Android App所占用d的手机内存(RAM)大小.App ...