Toyota Programming Contest 2024#2(AtCoder Beginner Contest 341)D - Only one of two(数论、二分)
链接
题面

题意
求第\(k\)个只能被\(N\)或\(M\)整除的数
题解
\([1,x]\)中的能被\(n\)整除的数有\(\lfloor \frac{x}{n} \rfloor\)个
\([1,x]\)中的能被\(m\)整除的数有\(\lfloor \frac{x}{m} \rfloor\)个
\([1,x]\)中的能被\(n\)或\(m\)整除的数有\(\lfloor \frac{x}{n*m} \rfloor\)个
\([1,x]\)中的只能被\(n\)或\(m\)中一个数整除的数有\(\lfloor \frac{x}{n} \rfloor + \lfloor \frac{x}{m} \rfloor-2*\lfloor \frac{x}{n*m} \rfloor\)个
然后可以观察到答案具有单调性,能被\(n 、 m\)整除的数的个数随答案的增大增大。
代码
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i = (a); i <= (b); ++i)
#define fep(i,a,b) for(int i = (a); i >= (b); --i)
#define pii pair<int, int>
#define pdd pair<double,double>
#define ll long long
#define db double
#define endl '\n'
#define x first
#define y second
#define pb push_back
#define vi vector<int>
using namespace std;
const int maxn=1e5+10;
void solve() {
int n,m,k;
cin>>n>>m>>k;
int lcm=n*m/__gcd(n,m);
int l=0,r=2e18;
auto check=[&](int tar){
if(tar/n+tar/m-2*(tar/lcm)>=k) return true;
return false;
};
while(l<r){
int mid=(l+r)>>1;
if(check(mid)) r=mid;
else l=mid+1;
}
cout<<l<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("1.in", "r", stdin);
int _;
// cin>>_;
// while(_--)
solve();
return 0;
}
总结
\([1,x]\)中的能被\(n\)整除的数有\(\lfloor \frac{x}{n} \rfloor\)个
\([1,y]\)中的能被\(n\)整除的数有\(\lfloor \frac{y}{n} \rfloor\)个
\([x,y]\)中的能被\(n\)整除的数有\(\lfloor \frac{y}{n} \rfloor - \lfloor \frac{x}{n} \rfloor\)个
Toyota Programming Contest 2024#2(AtCoder Beginner Contest 341)D - Only one of two(数论、二分)的更多相关文章
- KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解
KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...
- HHKB Programming Contest 2022 Winter(AtCoder Beginner Contest 282)
前言 好久没有打 AtCoder 了.有点手生.只拿到了 \(\operatorname{rk}1510\),应该上不了多少分. 只切了 \(\texttt{A,B,C,D}\) 四题. A - Ge ...
- AtCoder Beginner Contest 255(E-F)
Aising Programming Contest 2022(AtCoder Beginner Contest 255) - AtCoder E - Lucky Numbers 题意: 给两个数组a ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
- AtCoder Beginner Contest 184 题解
AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...
- atcoder beginner contest 251(D-E)
Tasks - Panasonic Programming Contest 2022(AtCoder Beginner Contest 251)\ D - At Most 3 (Contestant ...
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 136
AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...
随机推荐
- ClickHouse(14)ClickHouse合并树MergeTree家族表引擎之VersionedCollapsingMergeTree详细解析
目录 建表语法 使用场景 合并算法 使用例子. 资料分享 参考文章 VersionedCollapsingMergeTree引擎继承自MergeTree并将折叠行的逻辑添加到合并数据部分的算法中.Ve ...
- 开源IM项目OpenIM发布消息推送api,支持应用与IM互通深度融合
以办公场景为例,比如员工入职通知,放假通知等业务通知,由oa系统处理具体的业务逻辑,再调用消息推送api,触达到目标用户. 效果示例 以协同办公为例,员工收到系统推送的工作通知,有新任务需要处理. 员 ...
- go中x/sync/semaphore解读
semaphore semaphore的作用 如何使用 分析下原理 Acquire TryAcquire Release 总结 参考 semaphore semaphore的作用 信号量是在并发编程中 ...
- 物色到的 c# 模拟 http post get 请求 做下笔记
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...
- Redis安装,数据类型及常用命令
安装 - 可以使用yum 安装,要先配置epel源 ``` yum install -y redis ``` - 可以编译安装 ``` wget http://download.redis.io/re ...
- 使用symbolicatecrash工具符号化Crash日志
对于打包上线的APP,或者打包测试的APP,出现了崩溃并不能方便的把手机链接到电脑使用XCode自动符号化,此时手动符号化就是重要的选项. 1.查找符号化工具symbolicatecrash find ...
- 最新版Emlog采集发布插件-免费下载
推荐一款可以自动采集网页文章数据,并发布到Emlog网站的Emlog采集发布插件(兼容最新的Emlog Pro版本,也兼容之前的 Emlog 5.3 和 Emlog 6.0 版本),支持对接简数采集器 ...
- 【游戏】C语言实现扫雷游戏(超详细备注和解释)
C语言实现扫雷游戏 求个赞求个赞求个赞求个赞 谢谢 先赞后看好习惯 打字不容易,这都是很用心做的,希望得到支持你 大家的点赞和支持对于我来说是一种非常重要的动力 看完之后别忘记关注我哦!️️️ 文章目 ...
- 应用--WebApplication
应用--Program中的WebApplication 在6.0,微软团队对于NetCore做了很大的改变,其中有一个改变就是推出了新的托管模型--最小托管模型,使用该模型可以创建最小的web应用.( ...
- Jackson objectMapper.readValue 方法 详解
直接说结论方便一目了然: 1. 简单的直接Bean.class 2. 复杂的用 TypeReference 这样就完事了. public class TestMain2 { public static ...