How many integers can you find————(算术基本定理+容斥)

hdu1796(容斥原理模板,三种方法实现)How many integers can you find 题目大意:给定n和一个大小为m的集合,集合元素为非负整数。为1...n-1中能被集合里任意一个数整除的数字个数。n /*如果是枚举所有的1...n,则n必须要小,不然一定会超时 实现容斥的方法有:dfs,队列数组,二进制 */ //二进制实现容斥 //对自己无语了,连最小公倍数对算错,lcm(a,b)=a/gcd*b; #include #include #include using name 阅读详情

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<231,0<M<=100<N<231,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


给你一个数N,和一个具有M个数的集合,让你从[1,N−1][1,N−1]里边找到能够被集合里边任意一个数整除的数的个数,
eg:N=12,M={2,3}N=12,M={2,3}
所以ans=7ans=7

数字构成的集合就是

{2,3,4,6,8,9,10}{2,3,4,6,8,9,10}

//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    return !b?a:gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}
ll a[30];
int main()
{
    ll n,m;
    while(~scanf("%lld %lld",&n,&m))
    {
        memset(a,0,sizeof(a));
        for(ll i=0;i<m;i++)
        {
            scanf("%lld",&a[i]);
            if(a[i]<1||a[i]>=n)
            {
                i--;
                m--;
            }
         } 
        ll ans=0;
        for(ll i=1;i<(1<<m);i++){
            ll cnt=0;   ll LCM=1;
            for(ll j=0;j<m;j++){
                if(1&(i>>j)){
                    cnt++;
                    LCM=lcm(a[j],LCM);
                }   
            }   
            if(cnt&1)   ans+=(n-1)/LCM;
            else        ans-=(n-1)/LCM;
        }   
        printf("%lld\n",ans);
    }
    return 0;
}
别再死记硬背了!用Wireshark抓包实战,5分钟搞懂GRE、L2TP、IPsec的区别 本文通过Wireshark抓包实战,详细解析GRE、L2TP和IPsec三大隧道协议的核心差异与应用场景。从报文结构到配置示例,帮助网络工程师快速掌握这些协议的本质,提升VPN部署与故障排查能力。特别适合准备HCIP认证的工程师深化理解。 阅读详情

相关推荐

HCLR-Net: 混合对比学习正则化与局部随机扰动用于水下图像增强

独特贡献在于开发了一种处理负样本的新策略,既保留了负样本的统计特性,又防止网络过度剖析这些样本中的特征信息。通过根据每个通道特征的重要性对模型进行加权,我们可以增强富含上下文信息的通道,从而获得更准确、更详细的特征表示。AHA 模块利用垂直方向上的 Avgpool 和水平方向上的 Maxpool 来捕捉远程依赖关系和准确的位置信息,从而有效确定不同方向上的特征退化。对比学习策略通常旨在最小化正样本之间的欧氏距离,使预测图像更接近理想图像,同时最大化负样本与预测图像之间的距离,使它们进一步远离非理想表征。

G-Howe的博客 1456

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

wait 285

防反接电路、防倒灌电路、过流保护和ESP相关知识

1.开关电源给负载供电, 如果负载是电池或者其他感性负载(比如像 电机 有线圈 当电源突然断掉时 会产生感应电动势)时, 当220V断掉的时候,可能会出现 电池反向给开关电源 的 输出端 供电,导致开关电源的一些莫名损坏。2.系统在不同的 输出电压 之间 切换时,会存在高压电压倒灌到低压电压源中。例如:系统 有两个电源供电 比如 一个电池 一个 充电器 充电器的电压一般会高于电池 如果没有防倒灌的电路 可能充电器的电压会直接倒灌给电池 造成电池的损坏。

a_black_的博客 1万+

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

booty 491

Minio HTTPS证书配置实战:从申请到部署全流程

本文详细介绍了Minio HTTPS证书配置的全流程,从申请到部署,确保对象存储服务的安全性。内容包括证书类型选择、文件处理、服务配置调整及常见问题解决,帮助用户在生产环境中快速实现HTTPS加密传输,提升数据安全。

weixin_42638178的博客 431

如何在INCA中修改标定量的初始值,并刷回控制器

测试过程中,有些时候,标定量来不及修改,这就需要修改标定量的初始值了,又不想打开模型重新编译,因此直接在INCA中修改,然后再刷回控制器,就成了最佳选择,之前也学过,长时间不用,忘记怎么搞了,最近又用到了,这次记录一下,以后用到的时候,就不用在网上东翻西找了。截止到2023年11月24日,共找到了两种方法可以实现修改。

weixin_43406519的博客 4199

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

菜鸡的博客 222

SAP产品合规(Product Compliance)管理—规格主数据 CG02/CG02WB

SAP产品合规(Product Compliance)管理—规格主数据概览 CG02/CG02WB

Lucas1211的博客 1429

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

题目大意:有一个序列,大小为m,里面有m个不超过20的非负数,各不相同。要求在1-n中有多少个能被m个数中任意一个数整除。 题目思路:简单的容斥原理应用。就不说了直接上代码。 有两种方法,一种是DFS,一种是直接位元素枚举暴力(study from zhixiaoli) DFS:(速度较快) #include #include using namespace std; long long

Jason 890

关于STM32编译报错:Error: L6218E: Undefined symbol SystemInit (referred from startup_stm32f10x_md.o).

今天新建工程发现出现一个错误 —— …\Output\CG.axf: Error: L6218E: Undefined symbol SystemInit (referred from startup_stm32f10x_md.o). 但我觉得我的操作没有任何问题,而且配置和上一个文件比较是一模一样的。 于是我开始百度查询,然后发现了下面几个博客—— @weixin_44133391——STM32 编译错误 @dorlolok——iel5 编译报错 error: L6235E: More than one

纯粹,学术,热爱。 9402

深入探究贝叶斯网络(Bayesian Network):从基础原理到实际应用

贝叶斯网络,也称为信念网络或有向无环图模型,是一种概率图模型。它使用有向无环图(DAG)来表示随机变量之间的条件依赖关系。每个节点代表一个随机变量,边表示变量之间的条件依赖关系。贝叶斯网络作为一种强大的工具,通过结合概率论和图论,为复杂系统建模和推理提供了有效手段。无论是在医学诊断、故障检测还是自然语言处理等领域,它都展示了巨大的潜力。然而,其计算复杂度高、结构学习困难等挑战也需要我们在实际应用中不断优化算法和技术。希望通过本文,你能对贝叶斯网络有更深入的理解,并能够在实际项目中灵活应用这一强大工具。

qq_28791753的博客 5968

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) Problem Description Now you get a number N, and a M-integers set, you should find ou...

忘梦心的博客 322

【实战项目开发技术分享】如何设置机器人禁行区/虚拟墙

在现代机器人技术的日益发展中,路径规划是使机器人在复杂环境中安全、高效移动的关键部分。其中一个重要的问题是如何划定机器人的禁行区,以确保机器人不会进入危险区域或无法到达的地方。在本文中,我们将探讨一些关键策略,帮助机器人算法工程师更好地划定禁行区。代价地图可以通过多层叠加来实现,一般包括以下几个层级:静态地图层(Static Map Layer):由SLAM(Simultaneous Localization and Mapping)构建的静态地图。该层包含了环境中固定不变的地物信息,如墙壁、家具等。

xiewf的博客 1万+

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): 8059    Accepted Submission(s): 2403 Problem Descripti

超越自我就是成功 302

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

HDU - 1796How 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

Orz 284

怀旧版电脑GBC模拟器

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

简单容斥定理-hdu-1796-How many integers can you find

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1796 题目大意: 给一个n,给m个数,求出1~n中能够被m中某个数整除的数的个数。 解题思路: 简单容斥,不解释。 先对m个除掉0,然后数排序,然后容斥。每次求出前面的最小公倍数。 注意: 10 2 2 11   keys:4 10 2 11 2  keys:4  代码:

cc_again的专栏 1176

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

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) Problem Description Now you get a number N, and a M-integers set, you should fi...

weixin_30485291的博客 156

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 example,

Alex 816

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

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

codeswarrior的博客 537

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

qq_41555192的博客 242

J - 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=1

x311609001028的博客 322

NYOJ 993 How many integers can you find (数学)

How many integers can you find 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 给你三个数,n,m1,m2,找出所有小于n的能被m1或m2整除的数的个数。 输入输入包含多组测试数据,每组数据占一行。 0输出每组数据输出占一行。样例输入 12 2 3 样例输出 7 思路:小于n能被a整除的个

滴水穿石,慢慢积累,总会有成果 455

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

日月 362

B - 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-in...

W6791129的博客 229

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

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 exact

逆风的方向 更适合飞翔 3089

HDU 1796How 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): 3315    Accepted Submission(s): 937 Problem Descriptio

布生气 1644
上一篇: hdu4135Co-prime——容斥定理
下一篇: HDU1896 Stones————栈和队列(优先队列)
陶鸿杰
博客等级 码龄9年 93粉丝 298原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值