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

LPDDR5X内存技术解析:性能提升与优化策略 内存技术在现代计算系统中扮演着核心角色,其性能直接影响整体系统效率。LPDDR5X作为JEDEC最新标准,通过提升数据传输率至8533Mbps、优化能效比15%以上,并扩展突发长度至32字节,显著提升了移动设备的处理能力。这些改进特别适用于5G通信、AI加速(如昇腾芯片)及8K视频处理等高带宽需求场景。技术原理上,LPDDR5X引入了动态电压频率调整(DVFS)和可编程突发长度等创新机制,有效降低了实际应用中的延迟。在工程实践中,合理的PCB布局和信号完整性验证是确保高速稳定运行的关键。随着AI和8K应用的 阅读详情

一.题目链接:

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

 

手把手教你完成YOLOv9 PyQt5目标检测界面搭建,实现图片检测、视频检测、摄像头检测,可用于大论文凑工作量或毕设必备,全网最详细教程 目标检测是计算机视觉中的重要任务,广泛应用于安防监控、自动驾驶、智能家居等领域。YOLO系列模型由于其高效的检测速度和较高的准确率,成为目标检测任务的首选算法之一。本项目结合 YOLOv9与 PyQt5,构建了一个图形化界面,便于用户进行目标检测的操作和展示,实现对图片、视频和摄像头的实时目标检测,不仅可以用于大论文的工作量展示,还可以作为毕业设计。 阅读详情

相关推荐

S4HANA - Cost Elements成本要素

SAP这里面的配置逻辑很像,就是先建一个对象,然后不停给这个对象附加一些属性,给一个账户附加编号范围,附加账户组。所有模块的维度都在这个表里,看下图的GL,CO,COPA,AA,ML的都在ACDOCA里。要把这5个类型和六大要素对应,先得把六大要素和账户类型对应下(以下是个人理解,不知道对错):当然那个C是新来的,我觉得放在资产下面也行,就不画图了。S4的嵌入式分析是在业务逻辑都整套嵌入的情况下,预开发了数据模型,所以它能提供的就不仅是原始数据了,它能提供的是包含所有相关联的上下文的信息数据。

weixin_45689053的博客 2394

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

自抗扰控制ADRC原理解析及案例应用

ESO的设计通常基于系统动态方程的线性化或近似模型,其输出包括系统状态的估计值和总扰动的估计值。非线性状态误差反馈控制律(Nonlinear State Error Feedback,NLSEF)是ADRC的最后一个环节,负责根据ESO和TD提供的信息生成控制信号。ADRC的另一个重要发展方向是与其他控制策略的融合,如模糊控制、神经网络和自适应控制等,以进一步提高系统的鲁棒性和适应性。ADRC的参数主要包括扩张状态观测器(ESO)的参数和非线性状态误差反馈控制律(NLSEF)的参数。

LIUMAO99的博客 9285

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

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

1eHz的博客 3197

激光光束质量评估与光斑尺寸计算:从理论到MATLAB实践

本文详细解析激光光束质量评估与光斑尺寸计算的理论基础及MATLAB实践方法,重点介绍M²因子的测量与应用。通过高斯光束模型、CCD成像法和MATLAB算法实现,帮助读者掌握从理论到实践的完整流程,提升激光系统调试与评估能力。

weixin_29083373的博客 450

软件工程实验报告--用Visio绘制数据流图、ER图、状态图、软件结构图、程序流程图、系统流程图

用Visio绘制数据流图、ER图、状态图、软件结构图、程序流程图、系统流程图

m0_73814332的博客 4162

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

C51:PWM+舵机角度控制

PWM,英文名Pulse Width Modulation,是脉冲宽度调制缩写,它是通过对一系列脉冲的宽度进行调制,等效出所需要的波形(包含形状以及幅值),对模拟信号电平进行数字编码,也就是说通过调节占空比的变化来调节信号、能量等的变化,占空比就是指在一个周期内,信号处于高电平的时间占据整个信号周期的百分比,例如方波的占空比就是50%.脉冲宽度调制通过占空比编码模拟信号一个周期内,高电平占据时长的百分比如下图所示,最便宜的舵机sg90,常用三根或者四根接线,黄色为PWM信号控制。

qq_73379310的博客 3389

N Puzzle (数字推盘游戏)

N Puzzle (数字推盘游戏)

程永强 1793

【华为OD机试真题 新系统】1009、企业内部门的最大层级 | 机试真题+思路参考+代码解析(C++、Java、Py、C语言、JS)

【华为OD机试真题 新系统】1009、企业内部门的最大层级 | 机试真题+思路参考+代码解析(C++、Java、Py、C语言、JS) 华为od机试,华为od机试真题,华为od机试E卷,华为odE卷,华为od机试真题E卷,华为OD,华为OD机试,华为OD机试真题,华为od机考,华为od机试D卷,华为od机试真题D卷,华为od手撕代码,华为od,华为od机试C卷,华为od e卷,华为2026e卷,od机试,2026E卷,华为OD机试E卷,什么是华为od,华为od介绍,全面了解华为od,2026华为od,如何备战

KJ.JK 1417

工业4.0必备:C#上位机+数字孪生 生产线实时监控与智能预警系统(工业级实战)

数据割裂:PLC、传感器、工业相机的数据散落在不同系统,想看全局生产状态要切换N个软件,“数据孤岛”导致决策滞后;故障难预判:设备突发故障时,只能停机排查,平均故障响应时间超30分钟,一条生产线停工1小时损失超10万;可视化差:传统监控只有冰冷的数字和2D图表,设备运行状态、生产流程、物料流转无法直观感知,新人上手需3个月才能熟悉产线。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 660

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

OBC_开环扫频波特图拟合操作流程(结合 Simulink)

摘要: 本文详细介绍了基于Simulink的开环扫频波特图测试与拟合流程,适用于电源/控制系统(如LLC/PFC)的小信号分析。主要内容包括:1)前期准备(测试点选择、信号范围设定);2)Simulink建模方法(信号注入、数据记录);3)两种扫频方式(逐频正弦/Chirp扫频)的实现;4)MATLAB数据处理(FFT分析、传递函数拟合);5)线性分析工具使用技巧。重点强调了激励信号幅值控制、稳态数据采集及模型验证方法,并提供完整MATLAB脚本示例。该流程可有效获取系统频域特性,为控制器设计提供可靠依据。

Sumerking的博客 234

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

数学建模模型总结

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

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

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

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

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

假人有限元模型

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

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

余额充值