HDU 1796 How many integers can you find (数论之容斥)

Flash芯片的VCC上电到可操作时间过长 Flash的VCC上电到操作时间(tVSL)通常有最大值限制,如果超过这个时间,核心风险是状态机不同步和指令锁存错误。比如芯片内部振荡器可能已经尝试启动又休眠了,但主控却在这之后才发送指令,导致完全 misinterpreted。Flash芯片的(从电源上电到可以正常进行读写操作的时间)如果过长,会产生一系列负面影响简单来说,这个时间过长意味着电源上升速度太慢,违反了芯片的要求。 阅读详情

How many integers can you find

Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4950    Accepted Submission(s): 1416


Problem Description
  Now you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For example, N=12, and M-integer set is {2,3}, so there is another set {2,3,4,6,8,9,10}, all the integers of the set can be divided exactly by 2 or 3. As a result, you just output the number 7.
 

Input
  There are a lot of cases. For each case, the first line contains two integers N and M. The follow line contains the M integers, and all of them are different from each other. 0<N<2^31,0<M<=10, and the M integer are non-negative and won’t exceed 20.
 

Output
  For each case, output the number.
 

Sample Input
12 2 2 3
 

Sample Output
7
 

Author
wangye
 

简单容斥题目,求能被m个数中的任何一个数整除的数的集合,因为n个数是小于n的,所以乘法时为n-1,同时要排除0的影响

#include<cstdio>
#include<cstring>

int n,m;
int ans = 0;
int a[105],t = 0;
int gcd(int x,int y){
	while(y){
		int t = x%y;
		x = y;
		y = t;
	}
	return x;
}
void dfs(int now,int cnt,int x){
	x = a[now]/gcd(x,a[now])*x;
	if(cnt & 1)
		ans += (n-1)/x;
	else
		ans -= (n-1)/x;
	for(int i = now+1;i < t;i ++){
		dfs(i,cnt+1,x);
	}
}
int main(){
	while(~scanf("%d%d", &n, &m)){
		t = 0;
		ans = 0;
		for(int i = 0;i < m;i ++){
			int x;
			scanf("%d", &x);
			if(x) a[t++] = x;
		}
		for(int i = 0;i < t;i ++){
			dfs(i,1,a[i]);
		}
		printf("%d\n", ans);
	}
	return 0;
}


阿里云大模型ACP认证模拟考试(二) 摘要:在阿里云大模型高级工程师 ACP 认证暂无真题题库的现状下,模拟题具有重要意义。其依照真实考试设计,涵盖题型、题量与分值分布,助力考生熟悉考试框架,合理分配答题时间精力,提升效率。同时,模拟题紧扣官方课程,能帮助考生精准定位知识盲点,如大模型架构原理和通义千问应用实践等重点内容,以便针对性完善知识体系。此外,通过练习模拟题,考生可掌握不同题型的解题思维与技巧,快速洞察复杂题目本质,提高答题准确率。 阅读详情

相关推荐

在 STM32CubeIDE 中针对 STM32F407 移植 ThreadX

在 STM32CubeIDE 中针对 STM32F407 移植 ThreadX,不依赖盗版破解的Keil MDK、IAR等软件。

wangyuewu08的博客 3383

hdu 1796 How many integers can you find(容斥原理)

How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4303    Accepted Submission(s): 1235 Problem Descripti

youngkl博客 695

TensorFlow_PyTorch实战:构建AI人工智能回归模型

回归分析是机器学习的核心任务之一,用于预测连续型目标变量(如房价、股票价格、用户留存时间等)。基础线性回归模型的数学原理与代码实现多项式回归模型的过拟合处理与正则化技巧自定义数据集加载与数据预处理流程动态图(PyTorch)与静态图(TensorFlow)的编程范式对比模型评估指标与可视化分析方法核心概念:对比两大框架的架构设计,解析回归模型核心组件数学原理:推导线性回归的假设函数、损失函数及优化算法算法实现:提供TensorFlow和PyTorch的完整代码示例项目实战。

AI天才研究院 1443

HDU 1796 How many integers can you find

How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6362    Accepted Submission(s): 1829 Problem Descripti

窦小雨的小点子 4207

变压器励磁电感、励磁电流、漏感、漏感折算

励磁、漏感知识整理

HW-BASE的博客 1万+

如何在高版本的ubuntu系统里安装gcc4.1.2

1、下载安装包,一共五个http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-4.1/,根据计算机系统位数   进行下载,64位下载amd64结尾的。开头分别是cpp-4.1_4.1.2、g++-4.1_4.1.2、gcc-4.1-base_4.1.2、gcc-     4.1_4.1.2、libstdc++6-4.1 2、使用sudo d

lsr_fighting的博客 1940

[hdu 1796 How many integers can you find]容斥原理模板

hdu 1796 How many integers can you find 容斥原理模板 题目链接:hdu 1796 How many integers can you find  题意:给你一个数N,和有一个M个数的集合a1,a2,...,aM。0 分析:首先考虑特殊情况,N 当M==1,答案就是N / a1。 当M==2,答案就是N / a1 + N / a2 - N / l

Fighting! 495

光学传播仿真软件:ASAP_(1).ASAP软件介绍与安装

ASAP(Advanced System for Analysis and Propagation)是一款强大的光学传播仿真软件,广泛应用于光学系统的设计、分析和优化。它提供了丰富的建模工具和仿真功能,可以帮助用户从简单的光学元件到复杂的光学系统进行仿真。:支持光学、机械、热学等多物理场的联合仿真。:采用高精度的算法,确保仿真结果的准确性。:内置了大量的光学元件,如透镜、反射镜、棱镜、光栅等。:提供直观的用户界面,支持多种建模和仿真方式。:支持使用脚本语言进行二次开发,增强软件的定制能力。

kkchenjj的博客 1611

HDU 1796 How many integers can you find 【容斥】

<题目链接> 题目大意: 给你m个数,其中可能含有0,问有多少小于n的正数能整除这个m个数中的某一个。 解题分析: 容斥水题,直接对这m个数(除0以外)及其组合的倍数在[1,n)中的个数即可,因为可能会重复计算,所以在叠加的时候进行容斥处理,下面用的是位运算实现容斥。 1 #include <cstdio> 2 #include <cstrin...

weixin_30364147的博客 115

【Windows Server 2019】企业虚拟专用网络服务的配置和管理(上)

博文介绍了部署企业虚拟专用网的定义,目的,以及好处。同时说明了实验拓扑图以及虚拟专用网络的工作原理。

VMware, Windows, Linux, Cisco, Container, Kubernetes, Kali 1万+

Visual Studio Code ADT Extension 能不能连接 ECC,答案是可以,但真正的门槛在 ABAP 后端版本

Visual Studio Code 版 ABAP Development Tools(ADT)支持连接传统 SAP ECC 系统,关键不在于系统名称,而在于底层 SAP NetWeaver AS ABAP 版本是否达到最低要求(7.31 SP04 及以上)。只要系统已支持 Eclipse ADT,即可无缝使用 VS Code ADT,无需升级后端。SAP 通过复用原有 ADT 技术栈,将兼容性逻辑置于客户端,实现对老系统的持续支持。尽管初期侧重 ABAP Cloud 模型,但 1.1 及后续版本已全面覆盖

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

hdu1796 How many integers can you find(容斥)

题意: 给你一个数nnn,再给你mmm个数,问你小于nnn且至少是这mmm个数某个的倍数的数字有多少个。 思路 很明显的容斥,一开始用dfsdfsdfs写,已知Wa,后来看别人博客才知道有0输入,所以要去掉0…真坑。 dfsdfsdfs做法 ll f[N]; ll ans; ll n, m; ll LCM(ll a, ll b) { return a / __gcd(a, b) * b; } vo...

一身清贫怎敢入繁华 384

LLC电路细讲笔记(一)基波分析与等效负载电阻推导过程详解

产生励磁电流:励磁电感用于产生励磁电流(Im),这是系统维持磁场的关键。磁场存储:Lm的存在保证了变压器的磁通稳定,即使在负载变化时,仍然能保持有效的能量转移。降低开关损耗:由于Im不参与能量传输,且相对较小,能有效减少开关时的能量损耗,特别是在零电压开通时,有助于提升整体效率。形成谐振:Lr与谐振电容(Cr)共同决定谐振频率,使系统在特定频率下运行,达到能量转移的最佳状态。滤波:Lr的存在滤除高次谐波,确保谐振网络内流过的是接近正弦波的电流。

weixin_43199439的博客 1942

hdu 1796 How many integers can you find[经典容斥原理]

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1796 题目的意思:     让你

1567

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

怀旧版电脑GBC模拟器

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

hdu1796—How many integers can you find(简单容斥)

题目链接:传送门 How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8740    Accepted Submission(s): 2594 Pro

zhiyuanjiang的博客 313

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

HDU 1796 How many integers can you find (容斥原理)

题目链接:How many integers can you find 题面: How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5345   

David_Jett 1134

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

hdu1796 How many integers can you find(容斥)

题目链接:点这里!!!! 题意:给你一个n(n 题解:容斥裸体,注意a[i]=0的情况。 sum = 被1个数整除的个数-被2个数整除的个数+被3个数整除的个数-.... (注意被多个数整除的时候,我们利用的是lcm) 代码: #include #include #include #include #include #include #include #i

Zsss的博客 540

HDU 1796How many integers can you find(容斥原理)

How many integers can you find Time Limit:5000MSMemory Limit:32768KB64bit IO Format:%I64d & %I64u SubmitStatusPracticeHDU 1796 Description Now you get a number N,...

apk6909的博客 156

hdu 1796 How many integers can you find

文章目录题目链接: 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1796 十年前的题了。。。。 我一看这个,很常规的二进制来容斥,心里想的是10分钟搞定,结果被坑了。。。 ①:这道题有0,第一发RE了。。。 ②:给的数不是互质的,哇让我长见识了,平时我们做的题都是互质的来容斥,然后我就想把公共的因子提出来,结果还是WA了,因为会有1的影响,比如1...

帅气廖鹏飞 283

HDU - 1796 How many integers can you find (容斥)

题目链接点击打开链接  Now you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For example, N=

DS00HY的小博客 259

HDU - 1796 How many integers can you find

Now you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For example, N=12, and M-integer s...

weixin_43244265的博客 309

How many integers can you find (HDU 1796)

Now you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For example, N=12, and M-integer set is {2,3}, so there is another set {2,3,4,6,8,9,10}, a

Liuonao的博客 314

hdu1796 How many integers can you find(容斥)

题目链接 Problem Description Now you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For examp...

qq_42479630的博客 119

HDU1796 How many integers can you find 容斥原理/dfs

题源:https://vjudge.net/problem/13388/origin 题意:给你数n,m;再给你m个数,问你从1~(n-1)中有多少个数可以被m集合中任意一个数整除。m<=20. 思路:考虑到m很小,所以直接深搜即可。核心思想是容斥,和算年份那个(LightOJ1414)差不多。搜索到奇数层时加上,偶数层时减去。 ans便是最终答案。 下面是核心代码: void dfs(in...

枚举星星 173

HDU - 1796 How many integers can you find && HDU 4135 Co-prime (容斥)

How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7953    Accepted Submission(s): 2364 Problem Descripti

K键盘里的青春K 657

M - How many integers can you find HDU - 1796

Now you get a number N, and a M-integers set, you should find out how many integers which are small than N, that they can divided exactly by any integers in the set. For example, N=12, and M-integer s

Nowara_Shinnosuke的博客 345
下一篇: CF527A Playing with Paper
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值