Number Puzzle (ZOJ - 2836 ,容斥原理)

初识数据之特征选择 【代码】初识数据之特征选择。 阅读详情

一.题目链接:

ZOJ-2836

二.题目大意:

第一行给出 n, m  1 \leq N \leq 10,\, \,1\leq M\leq2e8

第二行有 n 个数

求在不大于 M 的非负整数中,有多少个数可以被这 n 个数中的任意一个整除.

三.分析:

容斥原理模板题存一下(偷笑.jpg)

四.代码实现:

#include <set>
#include <map>
#include <ctime>
#include <queue>
#include <cmath>
#include <stack>
#include <vector>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <ctime>
#define eps 1e-6
#define pi acos(-1.0)
#define ll long long int
using namespace std;

int a[15];

int gcd(int a, int b)
{
    if(!b)
        return a;
    gcd(b, a % b);
}

int Lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

ll solve(int n, int m)
{
    ll ans = 0;
    int End = 1 << n;
    for(int i = 1; i < End; ++i)///二进制枚举
    {
        int lcm = 1;
        int cnt = 0;
        for(int j = 0; j < n; ++j)
        {
            if((1 << j) & i)
            {
                cnt++;
                lcm = Lcm(lcm, a[j]);
            }
        }
        ans += 1ll * m / lcm * ((cnt & 1) * 2 - 1);
    }
    return ans;
}

int main()
{
    int n, m;
    while(~scanf("%d %d", &n, &m))
    {
        for(int i = 0; i < n; ++i)
            scanf("%d", &a[i]);
        ll ans = solve(n, m);
        printf("%lld\n", ans);
    }
    return 0;
}

 

快速入门必看!RT-DETR手把手训练自己的数据集去跑实验,基于 ultralytics 仓库源码改进,配置虚拟环境,准备数据集、训练、验证、推理测试 ,实现0到1的完整教学过程。 本文介绍了使用Ultralytics框架训练RT-DETR模型的全流程。首先需要创建Python 3.10虚拟环境,安装指定版本的PyTorch和相关依赖包。然后准备数据集,修改配置文件,并详细介绍训练、验证和推理三个核心步骤的代码实现。训练阶段使用RTDETR类加载模型配置,设置训练参数;验证阶段评估模型性能;推理阶段可对图片、视频等进行预测。文中还提供了清华大学镜像源加速下载,以及详细的参数配置说明,帮助用户快速搭建RT-DETR目标检测模型。 阅读详情

相关推荐

2023-11-20 MySQL ARM64 银河麒麟

背景 MySQL是常用数据库,Windows安装比较容易,笔者也有记录。现在国产化系统银河麒麟中安装,不同的是软件安装包不容易下载。一是安装的方式,再一个是MySQL本身的版本,网上很多文档说明其实都是对的,但是为什么那么多都不一样呢?就是MySQL本身的版本差异比较大,这些差异笔者也不是很清楚,但是不要用8和5.7的差异非常大,8即使安装的很顺利,在使用过程也会很多坑,导致我宁愿卸载8,也要重新...

jxmh1991@163.com 811

zoj 2836 Number Puzzle(容斥原理)

题目链接:传送门Number Puzzle Time Limit: 2 Seconds Memory Limit: 65536 KB Given a list of integers (A1, A2, …, An), and a positive integer M, please find the number of positive integers that are not gr

nhl19961226的博客 394

汇川EASY系列之以太网通讯(套接字socket做从站)

汇川EASY系列的以太网通讯中的Socket字通讯,不能使用配置的方式实现,只能通过指令完成,本文将详细说明

这是一个长期关注工控行业技术的博客,实现0-1的突破,期待您的关注和留言 3002

Numbers Puzzle/数字谜题 答案及思路 Numbers Puzzle地图攻略 VRChat VRC

Numbers Puzzle/数字谜题 答案及思路 Numbers Puzzle地图攻略 题解 VRChat VRC 。作者:★刀木日 X( Twitter ): @Dmr_Suon

1eHz的博客 3197

Oracle EBS Tax 四国实现详解:印度、巴西、美国、阿根廷

印度:务必启用India Localization模块,不要尝试用标准EBTax模拟GST逻辑 巴西:必须配置NF-e接口,建议聘请本地税务顾问设置CFOP和NCM代码映射 美国:跨州业务强烈建议购买Vertex或Avalara服务,自建税率表维护成本极高 阿根廷:注意1:1:1架构限制,提前规划Legal Entity和OU结构

金牌架构师 260

PHP与Node.js的对比及优缺点分析

PHP和Node.js是两种常用的服务器端编程语言,它们在不同的应用场景下各有优势和劣势。本文将全方位比较PHP和Node.js的特点,以及它们在编程中的优缺点,并提供相应的源代码示例供参考。需要注意的是,本文只是对PHP和Node.js的一些优缺点进行了简要介绍,实际应用中还需要考虑其他因素,如团队经验、项目规模和预算等。最终的选择应该基于全面的评估和需求分析。PHP:PHP是一种同步阻塞的编程语言,它的处理方式是一次只处理一个请求。Node.js:Node.js的性能较高,特别适合处理高并发的请求。

ByteSparkX的博客 888

zoj_2836 Number Puzzle

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1836   //C++代码 #include using namespace std; int n,m,ans,a[11]; int gcd(int a,int b){ return b==0? a:gcd(b,a%b); } int lcm(int a,i

永恒国度 684

深度学习与西储大学轴承数据集(一)

西储大学数据集介绍

weixin_50642818的博客 1万+

N Puzzle (数字推盘游戏)

N Puzzle (数字推盘游戏)

程永强 1793

【无人机路径规划】基于强化学习实现多无人机路径规划

【无人机路径规划】基于强化学习实现多无人机路径规划

k8291121的博客 1656

13、离散时间系统建模与分析

本文系统介绍了离散时间系统的建模与分析方法,涵盖连续时间模型的离散化过程、系统稳定性判断准则、输入输出模型转换方法以及有限脉冲响应和阶跃响应模型的应用。通过多个示例详细展示了不同系统在离散化过程中的特性变化,并探讨了采样间隔对系统动态特性的影响。此外,文章还分析了时间延迟的处理方法,并总结了关键知识点及操作步骤,为离散时间系统的实际应用提供了理论基础和实践指导。

2w3e4r5t6y的博客 189

ZOJ 2836 Number Puzzle 题解

题面 lcm(x,y)=xy/gcd(x,y)lcm(x1,x2,···,xn)=lcm(lcm(x1,x2,···,xn-1),xn) #include <bits/stdc++.h> using namespace std; long long n,m; long long a[1010]; long long gcd(long lon...

weixin_30437481的博客 348

32位快速加法器设计

32位快速加法器设计

好好学习,天天向上 3290

ZOJ 2836 Number Puzzle(容斥原理)

题意:求[1, M]中因子包含A数列里数的个数。 思路:容斥。奇加偶减。 #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long L

ACMiao的博客 421

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

ZOJ2836 Number Puzzle【容斥原理】

题目大意: 给N个整数,和一个整数M。求小于等于M的非负整数(1~M)中能被这N个数中任意一个 整除的数的个数。 解题思路: 设S1为1~M中能被第一个整数A1整除的集合,S2为1~M中能被第二个整数A2整除的集合。 …… Sn为1~M中能被第N个整数An整除的集合。然后每个集合个数,其实就是M / An。 再根据容斥原理,求集合并集的元素个数即可。

程序员充电站(itcharge) 1069

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

ZOJ 2836 Number Puzzle (容斥原理)

理解的好辛苦啊,,ym final爷,几分钟就能A出来!!  二进制真是好东西啊   #include "string" #include "iostream" #include "cstdio" #include "cmath" #include "set" #include "queue" #include "vector" #include "cctype" #inc

潮鸣り 437

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

[容斥原理] zoj 2836 Number Puzzle

题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1836 Number Puzzle Time Limit: 2 Seconds      Memory Limit: 65536 KB Given a list of integers (A1, A2, ..., An), and a posi

cc_again的专栏 1062

zoj 2836 Number Puzzle(容斥原理)

zoj 2836 Number Puzzle(容斥原理)

1464

【ZOJ-2836-Number Puzzle】 容斥原理

ZOJ-2836-Number Puzzle 题意就是给出一个整数m,一个具有n个元素的数组,求出1-m中有多少个数至少能整除n数组中的一个数 这道题就是经典的给出某个数组去组合的问题,只要对当前选中元素取lcm即可 容斥原理第五题代码 #include&lt;stdio.h&gt; #include&lt;iostream&gt; #include&lt;algorithm&gt; ...

lajiyuan的博客 255

ZOJ2836---Number Puzzle(容斥原理)

Given a list of integers (A1, A2, …, An), and a positive integer M, please find the number of positive integers that are not greater than M and dividable by any integer from the given list.InputThe inp

Alex 1270

Number Puzzle ZOJ - 2836(容斥原理)

Number Puzzle ZOJ - 2836 题意:求不大于m的数中,有多少可以被数组a中的数整除。 二进制枚举,容斥 1 #include <bits/stdc++.h> 2 using namespace std; 3 int a[11]; 4 int n,m; 5 int gcd(int a,int b){ 6 return b...

weixin_30587025的博客 152

ZOJ - 2836 Number Puzzle —— 容斥原理

题意: 问1到m之间有多少个数能被序列的任意一个数整除 思路: 容斥,序列最多只有10个,用二进制优化一下,跑一遍容斥 #include &lt;iostream&gt; #include &lt;cstdio&gt; #include &lt;algorithm&gt; #include &lt;cstring&gt; #include &lt;queue&gt; #include &...

Lngxling的博客 310

【ZOJ - 2836 】Number Puzzle (容斥原理)

题干: Given a list of integers (A1, A2, ..., An), and a positive integer M, please find the number of positive integers that are not greater than M and dividable by any integer from the given list.   ...

xuanweiace的博客 821

ZOJ 2836 - Number Puzzle(容斥原理)

Given a list of integers (A1, A2, …, An), and a positive integer M, please find the number of positive integers that are not greater than M and dividable by any integer from the given list. Input The ...

Steve·Curcy 263

B - Number Puzzle ZOJ - 2836(容斥原理 数学)

Given a list of integers (A1, A2, …, An), and a positive integer M, please find the number of positive integers that are not greater than M and dividable by any integer from the given list. Input The ...

starlet_kiss的博客 357

ZOJ 2836 Number Puzzle(容斥原理)

给出1到10的十个数字,要求输出不大于m的数字能被其中任意一个整除的数字有多少个 简单的熔池原理,我们用二进制枚举每个数字的选择情况,然后当选择的数字为奇数时将总数加上m/gcd   偶数时减去 #include #include #include #include #include #include #include #include #include #i

宝树啊宝树 657
上一篇: Fibonacci again and again (HDU - 1848 ,博弈 SG 函数水题)
下一篇: Highway Project (ZOJ - 3946,双权值 spfa)
The___Flash
博客等级 码龄8年 79粉丝 223原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值