UVA10325--- The Lottery (容斥)

【汽车 OTA 】差分升级 汽车 OTA 差分升级,本质是在整包 OTA 的基础上,通过“只传变化”的方式,大幅减少下载数据量、时间和成本,是当前车端软件升级的主流方向之一。 阅读详情

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<
2
31
) 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

容斥原理的简单应用

/*************************************************************************
    > File Name: uva10325.cpp
    > Author: ALex
    > Mail: zchao1995@gmail.com 
    > Created Time: 2015年05月27日 星期三 20时44分29秒
 ************************************************************************/

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <set>
#include <vector>

using namespace std;

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;

LL num[20];

LL gcd(LL a, LL b) {
    return b ? gcd(b, a % b) : a;
}

int main() {
    LL n;
    int m;
    while (cin >> n >> m) {
        for (int i = 0; i < m; ++i) {
            cin >> num[i];
        }
        int ans = 0;
        for (int i = 1; i < (1 << m); ++i) {
            int bits = 0;
            LL cur = 1;
            for (int j = 0; j < m; ++j) {
                if (i & (1 << j)) {
                    ++bits;
                    cur = cur / gcd(num[j], cur) * num[j];
                }
            }
            if (bits & 1) {
                ans += n / cur;
            }
            else {
                ans -= n / cur;
            }
        }
        cout << n - ans << endl;
    }
    return 0;
}
数字逻辑Fundamentals of Digital Logic with Verilog Design | 3rd Edition Solutins Chapter 3(step by step) 第三章3-1~3-27全部习题解析和代码模块 阅读详情

相关推荐

LaTeX双栏浮动结构实战:用dblfloatfix解决跨栏图表排版难题

本文深入探讨了LaTeX双栏浮动结构在学术论文排版中的常见问题,特别是IEEE会议论文中的跨栏图表定位难题。通过介绍dblfloatfix包的整合解决方案,帮助用户实现精准的底部定位和浮动顺序保持,提升排版效率与质量。

weixin_30872499的博客 446

【UVA10325】The Lottery——简单容斥定理

题意:给你一个数组,问[1,n][1,n]中有多少个数不能整除数组的任何一个数 分析:对于这种问题,我们可以求其逆问题,就是在区间[1,n]中存在多少数可以整除数组中的只少一个数 对于a[i],可以整除它的数的数量为Ai=na[i],但是我们不能将每一个数的数量加起来,因为存在重复元素a[i],可以整除它的数的数量为A_i = \frac{n}{a[i]},但是我们不能将每一个数的数

绝尘 995

yolov8的Detect层详解(输出维度改动)

对于部署端需要拿到onnx的output进行后处理,但是基于anchor_free的yolov8输出是1*(4+cls)*8400,不是我们常见的ncwh格式,所以对Detect层进行了学习,分享一下体会。

yjcccccc的博客 2万+

UVa 10325 - The Lottery

题目:给你一个数n以及m个数字,问n

小白菜又菜 1491

WSL2深度学习环境搭建:CUDA与PyTorch配置指南

CUDA是NVIDIA的并行计算平台,通过显卡驱动直接调用GPU资源,为深度学习提供加速支持。在Windows系统中,WSL2以轻量级虚拟化技术运行完整Linux内核,实现GPU直通,让PyTorch等框架能高效利用本地显卡。这种方案避免了双系统切换,兼顾开发便利与计算性能,适用于图像分类、模型训练等场景。本文详细记录在WSL2中配置Ubuntu、CUDA Toolkit、cuDNN及PyTorch的完整流程,并分享常见问题排查与性能优化经验。

weixin_30522983的博客 221

基于STM32F103C8T6的光伏发电量检测系统设计与Proteus仿真

在嵌入式系统开发中,数据采集与处理是核心基础技术,广泛应用于工业监控、新能源管理等领域。其原理是通过模数转换器(ADC)将模拟信号(如电压、电流)数字化,结合定时器实现周期性采样,再通过微控制器(MCU)进行实时计算与处理。这项技术的价值在于能够将物理世界的连续信号转化为可分析的数字信息,为状态监控、效率分析和智能控制提供数据基础。在光伏发电等新能源应用场景中,对发电参数的实时监测是评估系统性能、进行能量管理的关键。本文聚焦于一个具体的工程实践案例:使用高性价比的STM32F103C8T6微控制器,构建一个

weixin_30693683的博客 378

A. Hit the Lottery(贪心)

A. Hit the Lotterytime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAllen has a LOT of money. He has nn dollars in the bank. For security reasons, he...

JiaYao的博客 723

从安装到出图:一份给振动测试新手的LMS Test.Lab 2021完整避坑手册(含许可证更新和常见弹窗解决)

本文为振动测试新手提供LMS Test.Lab 2021的完整使用指南,涵盖安装配置、许可证更新、数据采集到频域后处理的全流程。特别针对常见弹窗错误提供解决方案,并详细讲解Colormap时频图分析技巧,帮助用户快速掌握振动数据分析核心技能。

weixin_29268331的博客 1045

UVA - 10325The Lottery(容斥)

题意: 求1~n中不能被给定m个数中任意一个数整除的数的个数 思想: n-(1~n中至少能被m个数中的一个整除的数个数) 解法:     容斥原理的思想,多减的数要加回去 比如第一组样例:10 - 能被2整除的数的个数 - 能被3整除的数的个数 + 能被6整除的数的个数 第二组样例:20-能被2整除的数的个数-能被4整除的数的个数+能被4整除的数的个数(2,4的最小公倍数)

Rain 439

嵌入式铁头山羊stm32:一文总结

本文是一篇STM32嵌入式开发的综合知识总结,涵盖了STM32基础概念、GPIO、通信协议、外设驱动等核心内容。文章首先介绍了STM32的基本概念和型号含义,然后详细讲解了GPIO的8种工作模式及实验案例。接着重点阐述了USART、I2C、SPI三种通信协议的原理和实现方法,包括硬件连接、编程接口和实验应用。此外还介绍了OLED显示原理、中断系统、定时器、ADC转换等关键技术,每个模块都配有对应的实验案例和代码实现参考。文章内容全面系统,既包含理论知识,又提供实践指导,适合作为STM32开发的快速参考手册。

古泽汉书的博客 2809

零基础DSP实战TMS320F28035:第九节,ADC比较器&EPWM

ADC比较器框图如下所示:-电压-----------------------------输出-电压A>电压B------------------ 1-电压A

sinat_30943509的博客 2538

UVA10325 The Lottery(容斥)

题意: 给定n,m,和一个长度为m的数组a 问[1,n]中有多少个数,不被a中的任何数整除 数据范围:n<=2^31,m<=15,a(i)<=n 解法: 反过来想,用总个数减去被整除的个数 答案=n-至少被一个数整除+至少被两个数整除-至少被三个数整除 因为m只有15,所以二进制枚举就行了(2^15=32768) 二进制枚举整除的k个数 根据前面我们推出的式子,根据二进制1的位数,奇减偶加就行了 ps: 代码中lcm不知道会不会爆longlong,不会算 理论上int范围内的15个大质数,

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 338

基于Lumerical的1550 nm InGaAs/InP与InGaAs/InAlAs APD设计与功率饱和度优化

摘要 本研究利用Ansys Lumerical软件对1550 nm激光雷达应用的InGaAs/InP和InGaAs/InAlAs雪崩光电二极管(APD)进行仿真设计与优化。通过FDTD光学仿真获取光吸收分布,结合CHARGE模块的电学仿真分析暗电流、光电流及雪崩增益特性。重点研究了两种材料体系的性能差异,并针对近距离强反射导致的功率饱和问题提出结构优化方案。仿真结果表明,InGaAs/InAlAs APD具有更优的过量噪声特性,而优化的电荷层设计可显著提升器件的功率饱和阈值。研究提供了完整的仿真流程与代码实

huanghm88的专栏 103

UVa 10325 The Lottery 【容斥】【入门】

题目链接:UVa 10325 The Lottery Description: 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

咸鱼の小窝 627

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

UVA 10325 - The Lottery ( 容斥 )

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1266 题        意:求出1~n个数中不能被输入的m个数任意一个数整除的数的个数。 思        路:利用容斥原理计算n-(1^n中质数能被m个数中的一个整除的数的个数。    

Seraphimon的博客 547

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

UVA10325:The Lottery (容斥)

题意:给出N和M个数,要求1~N里面有多少个数,其不能被这M个数任意一个整除。 思路:简单容斥,使用队列数组优化。 # include # include # include # include # define ll long long using namespace std; ll n, m, a[100000]; ll gcd(ll a, ll b) { return

junior19的博客 315

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

UVA 10325 - The Lottery(容斥)

以前做过的一个题,忘记/gcd了,看来需要把以前的东西看一下啊。 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <cmath> 5 #include <algorithm> 6 using namespace ...

weixin_30855761的博客 122

The Lottery UVA - 10325(容斥,二进制枚举)

题意:给m个数字,求1到n中不能被m个数字中任意一个数字整除的数的个数。 int a[20]; int main() { //freopen("in.txt", "r", stdin); ll n, m; while (cin >> n >> m) { f(i, 1, m)scanf("%d", &a[i]); ll ans = 0; f(i, 1, (1 << m) - 1) { int cot = 0; ll LCM = 1

qq_43543086的博客 144

UVa10325 - The Lottery(容斥+最小公倍数)

The Lottery  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 nu

mowayao的专栏 840

UVA 10325 The Lottery 容斥原理

UVA 10325 The Lottery 容斥原理 链接:UVA 10325 The Lottery 题意:给你两个正整数n,mn,mn,m,然后给你mmm个正整数a1,a2,⋅⋅⋅,ama_1,a_2,···,a_ma1​,a2​,⋅⋅⋅,am​,让你找出111~nnn中有多少个数不是这mmm个数的倍数? 题解:显然,我们会想到用nnn减去n/ain/a_in/ai​,但是这样会有一些元素会...

weixin_43855330的博客 234

UVA 10325 The Lottery

容斥原理求集合并集. 这里的集合就是给出的M个数,每个数的倍数(小于等于N)就是一个集合. 先求出最小公倍数,然后 N/最小公倍数 就可以得出每个子集的元素数量. #include #include using namespace std; long long gcd(long long a, long long b){ return b == 0 ? a : gcd(b, a %

蚂蚁大战大象 1436

UVA10325 The Lottery(容斥原理)

题意: 给n,m,和m个数(k1~km)。求1~n中有多少个数不是(k1~km)中任意一数的倍数。   题解: 容斥模板题。反面考虑,a的倍数有n/a个;既是a,也是b的倍数,即lcm(a,b)的倍数有n/lcm(a,b)个。是a,b,c的倍数,即lcm(a,b,c)的倍数有n/lcm(a,b,c)个。   #include #include #include using na

Strangedbly 1065

UVA10325 The Lottery(容斥原理)(简单)

给n,m,和m个数(k1~km)。求1~n中有多少个数不是(k1~km)中任意一数的倍数。 题解: 容斥模板题。反面考虑,a的倍数有n/a个; 既是a,也是b的倍数,即lcm(a,b)的倍数有n/lcm(a,b)个。 是a,b,c的倍数,即lcm(a,b,c)的倍数有n/lcm(a,b,c)个。 #include&amp;amp;lt;iostream&amp;amp;gt; #include&amp;amp;lt;cstdio&amp;amp;gt;

lance~crazy 481

UVA10325 The Lottery [容斥原理]

容斥入门题一道,蒟蒻的第一道自己yy出的容斥 其实就是你统计出nnn以内能被整除的个数,再用总个数减去可行的个数,就是不可行的个数啦,但是对于2312312^{31},显然不能枚举,那么就容斥吧。 我们先对于一个数xxx,nnn以内能被他整除的个数就是n/xn/xn/x向下取整这么多个,所以就可以O(1)O(1)O(1)的统计出这个个数。但对于多个数字,如果你加上对于xxx和yyy分别的能被整...

TimeTraveller-VictoryCzt 258

uva - The Lottery(容斥,好题)

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

weixin_34405354的博客 168
上一篇: Codeforces Round #305 (Div. 2)D---Mike and Feet(单调栈)
下一篇: hdu5245---Joyful(期望)
tokers
博客等级 码龄12年 71粉丝 700原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值