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

Win10 Rational Rose 安装教程 在此教程中我们需要四个文件,点此下载[提取码:ig33] 其中第一个为2007的安装包,第二个为破解文件 前言 很多小伙伴反应说会出现几天后就到期的问题,包括我也出现了该问题,如果你已在其他地方安装好了文件且破解成功,且但几天后到期,如果可以使用更改时间的方式打开,那么可以跳过接下来的教程,直接看第三节,我们采用批处理的形式一键完成从修改时间到打开最后改回来的方法解决此问题 一、安装软件 解压缩两个安装包,进入 Rational Rose文件夹 选择setup.exe开始安装 按照图示依次点击 阅读详情

一.题目链接:

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;
}

 

ICNN实现入侵检测的思路与源码(CIC-IDS-2017) 基于ICNN实现入侵检测,可用于现实网络 阅读详情

相关推荐

Windows Server上OpenVPN 2.4.8双因子认证实战:账号密码+证书,附一键脚本

本文详细介绍了在Windows Server上部署OpenVPN 2.4.8双因子认证(账号密码+证书)的实战方案,包括架构设计、证书体系规划、环境准备、服务器端配置及客户端自动化部署。通过一键脚本和优化配置,提升企业VPN的安全性和运维效率,特别适合金融、医疗等对安全性要求高的行业。

weixin_29231221的博客 465

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

实验室LIMS系统选型指南:从赛默飞到金现代,5大主流方案横评

本文深入分析了实验室LIMS系统选型的5大核心维度,包括架构选择、行业适配性、合规性设计、智能化程度和成本模型。通过对比赛默飞、金现代等主流厂商的优劣势,提供实战避坑策略,帮助实验室管理者做出明智决策,提升运营效率和合规水平。

plum99的博客 259

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

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

1eHz的博客 3197

【2021工业图像异常检测文献】DRÆM: 基于判别性训练的重建嵌入表面异常检测方法

DRÆM – A discriminatively trained reconstruction embedding for surface anomaly detection

qq_1532145264的博客 1477

Open Interpreter利用Code Interpreter实现本地化

作为一个可以在本地环境中运行的工具,Open Interpreter可以访问互联网,没有文件大小和运行时间的限制,并且可以利用任何包或库。去年7月,OpenAI发布了一个强大的插件,名为Code Interpreter(代码解释器),它可以根据用户的自然语言需求生成并执行代码解决方案,帮助完成各种任务,如数据分析、图表创建和文件编辑等。Open Interpreter不仅是一个编码解释器,它还是一个强大的工具,专注于处理复杂任务,将GPT-4代码解释器的强大功能与本地开发环境的灵活性完美结合在一起。

DigitalChina_DCG的博客 1794

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

高精度计算Π的值(C语言)

题目要求 限制使用双向链表作存储结构,请根据用户输入的一个整数(该整数表示精确到小数点后的位数,可能要求精确到小数点后500位),高精度计算PI值。可以利用反三角函数幂级展开式来进行计算。 输入5 输出3.14159 思路分析 反三角函数幂级展开式 由公式可以看出,只要计算出来每一个R(n)的值再相加取二倍就可以得到Π的值。 经过推算,要是令R(1)=2,只需要将每个R(n),相加即可。 因...

weixin_46251155的博客 8033

N Puzzle (数字推盘游戏)

N Puzzle (数字推盘游戏)

程永强 1793

RealSense D435i深度相机实战:从像素坐标到三维空间的精准映射(Python实现)

本文详细介绍了使用RealSense D435i深度相机实现从二维像素坐标到三维空间坐标精准映射的两种Python实战方法:深度图反投影法与点云直接查找法。文章涵盖环境搭建、相机对齐、代码实现、性能对比及与YOLO等检测模型结合的进阶应用,并提供了关键的避坑指南和参数调优建议,帮助开发者在机器人、三维重建等项目中高效应用。

weixin_29291573的博客 382

SAP 标准 CDS View 到底能不能用 CDS Extension View 扩展,我们在项目里应该这样判断

文章摘要:判断SAP标准CDS视图(如A_PRODUCT)能否扩展字段,不能仅凭命名或@Metadata.allowExtensions判断,需检查DDL源码中的@AbapCatalog.viewEnhancementCategory值。#PROJECTION_LIST允许扩展字段,#NONE则禁止。聚合视图需额外包含#GROUP_BY,UNION视图需#UNION。CDS View Extension用于新增字段,Metadata Extension仅用于添加注解。在ABAP Cloud环境中还需检查AP

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 100

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

智能硬件产品 App 全球发布 第 1 章:全球 App 发布战略设计

本章阐述智能硬件 App 全球发布战略,涵盖市场分析、竞争格局、用户画像及资源配置。通过制定可执行的全球化推广路径,整合地区法规合规、渠道分发策略与营销活动设计,助力团队快速进入主流商店并确立品牌影响力。同时构建可量化的 KPI 监控体系,指导项目进度追踪与效果复盘,确保产品迭代持续优化,降低运营总成本。

moton2017的博客 156

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

数学建模模型总结

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

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

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

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

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

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

[容斥原理] 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、付费专栏及课程。

余额充值