The Sports Association of Bangladesh is in great problem with their latest lottery ‘Jodi laiga Jai’. There are so many participants this time that they cannot manage all the numbers. In an urgent meeting they have decided that they will ignore some numbers. But how they will choose those unlucky numbers!!! Mr. NondoDulal who is very interested about historic problems proposed a scheme to get free from this problem.
    You may be interested to know how he has got this scheme. Recently he has read the Joseph’s problem.
    There are N tickets which are numbered from 1 to N. Mr. Nondo will choose M random numbers and then he will select those numbers which is divisible by at least one of those M numbers. The numbers which are not divisible by any of those M numbers will be considered for the lottery.
    As you know each number is divisible by 1. So Mr. Nondo will never select 1 as one of those M numbers. Now given N, M and M random numbers, you have to find out the number of tickets which will be considered for the lottery.
Input
Each input set starts with two Integers N (10 ≤ N < 231) and M (1 ≤ M ≤ 15). The next line will contain M positive integers each of which is not greater than N.
    Input is terminated by EOF.
Output
Just print in a line out of N tickets how many will be considered for the lottery.
Sample Input
10 2
2 3
20 2
2 4
Sample Output
3
10

问题链接:UVA10325 The Lottery
问题简述:给定整数n和m,以及m个正整数,求1~n中不能被这m个数字整除的数的个数?
问题分析:数论问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA10325 The Lottery */#include <bits/stdc++.h>using namespace std;const int M = 15;
int a[M];inline long long LCM(long long a, long long b)
{return a / __gcd(a, b) * b;
}int main()
{int n, m;while (scanf("%d%d", &n, &m) == 2) {for (int i = 0; i < m; i++)scanf("%d", &a[i]);int e = 1 << m, ans = n;for (int i = 1; i < e; i++) {long long lcm = 1LL;int cnt = 0;for (int j = 0; j < m; j++)if (i & (1 << j)) {lcm = LCM(lcm, a[j]);cnt++;}if (cnt & 1) ans -= n / lcm;else ans += n / lcm;}printf("%d\n", ans);}return 0;
}

UVA10325 The Lottery【GCD+LCM】相关推荐

  1. HDU2028 Lowest Common Multiple Plus【GCD+LCM】

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...

  2. 【CF1230E】Kamil and Making a Stream【GCD性质】【暴力vector】

    传送门 题意:给一棵带点权的有根树,求所有满足uuu是vvv的祖先的路径(u,v)(u,v)(u,v)的路径上所有点权的gcdgcdgcd的和模1e9+71e9+71e9+7. N≤100000N \ ...

  3. jzoj2700-数字【数论,LCM】

    正题 luogu题目链接:https://www.luogu.org/problemnew/show/P4193 题目大意 定义一个函数D(x)D(x)D(x)和S(x)S(x)S(x),S(x)S( ...

  4. 【备战蓝桥】JavaB组算法小讲解——GCD和LCM

    大家好,这里是祁十一!今天为大家整理了一下GCD和LCM的内容. 目录 一.GCD(最大公约数) 1.定义 2.性质 3.代码实现 <1>Java自带函数 <2>辗转相除法 二 ...

  5. 【HDU4497 GCD and LCM】

    题意:已知l,g其中g=gcd(x,y,z),l=lcm(x,y,z),问有x,y,z多少种组合使得关系成立.         题解:已知x%g=y%g=z%g=0,l%x=l%y=l%z=0,所以l ...

  6. GCD and LCM Aizu - 0005(辗转相除)+GCD LCM Inverse POJ - 2429(java或【Miller Rabin素数測试】+【Pollar Rho整数分解】)

    题目:GCD and LCM Aizu - 0005 Write a program which computes the greatest common divisor (GCD) and the ...

  7. 【数论Day1】 最大公约数(gcd)题目

    20170529-3数论_gcd 题解: http://www.cnblogs.com/ljc20020730/p/6919116.html 日期 序号 题目名称 输入文件名 输出文件名 时限 内存 ...

  8. 【学习笔记】关于最大公约数(gcd)的定理

    [学习笔记]关于最大公约数(gcd)的定理 手动博客搬家: 本文发表于20181004 00:21:28, 原地址https://blog.csdn.net/suncongbo/article/det ...

  9. 【UOJ#33】【UR #2】树上GCD(长链剖分/根号分类讨论)

    [UOJ#33][UR #2]树上GCD 求解树上两个点到lca的距离的最大公约数是k的对数 首先我们很容易就想到莫比乌斯反演,那么利用倍数形式,我们只需要求解是i的倍数的对数. 考虑枚举lca,这个 ...

最新文章

  1. oracle or索引失效_oracle数据库中索引会失效的几种情况
  2. 9 Unconstrained minimization
  3. findler mac 隐藏文件_fiddler使用实例之----------查找隐藏的真实地址!!!!
  4. linux设备驱动模块引用和依赖
  5. linux的initrd.img的解压和打包
  6. Codeforces Round #191 (Div. 2) A. Flipping Game【*枚举/DP/每次操作可将区间[i,j](1=i=j=n)内牌的状态翻转(即0变1,1变0),求一...
  7. 基于JAVA+SpringMVC+MYSQL的人事管理系统
  8. 记参加 2022 Google开发者大会
  9. 呆老大,奸老二,家家有个坏老三(转载自:http://soulogic.3322.org/blog/read.php/165.html)
  10. web项目修改favicon.ico图标
  11. 过去一年,网易新闻是如何甩开对手的?
  12. oracle heavy swapping,11gR2新特性:Heavy swapping observed on system in last 5 mins.
  13. App Store 中国区已支持人民币支付
  14. ManualResetEvent使用
  15. 细谈中医------疥,疮,痘的治疗方法
  16. ZOJ 3861 安卓图案锁屏 DFS深搜
  17. 工作流+口才思维导图模板
  18. 工作几年,涨薪4K遭拒,后一天我就裸辞走了···
  19. 赖世雄英语从头学 下载
  20. 转载:Nginx是什么(1.1)《深入理解Nginx》(陶辉)

热门文章

  1. 如何使用GDAL重采样图像
  2. Cocos2d-html5 2.2.2的屏幕适配方案
  3. Jaakko isalo谈《愤怒的小鸟》创意来源
  4. git:Failed to connect to github.com port 443:.....
  5. 【java学习之路】(java SE篇)(练习)关于常用类的心血来潮小练习
  6. Linux添加相对库路径,Linux C编程(8) 使用相对路径加载动态库-rpath和$ORIGIN
  7. linux创建云主机内存不足,云主机DC2 Linux系统CPU与内存占用率高导致无法登录
  8. 新增页和列表页遇到的坑
  9. lcl手术和飞秒区别_关于全飞秒价格的那些事!你知道吗?
  10. 用友仓库档案boot直接访问html,图文解析用友仓库软件怎样设置档案?