链接

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(数论、二分)的更多相关文章

  1. KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解

    KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) 题解 哦淦我已经菜到被ABC吊打了. A - Century 首先把当前年 ...

  2. HHKB Programming Contest 2022 Winter(AtCoder Beginner Contest 282)

    前言 好久没有打 AtCoder 了.有点手生.只拿到了 \(\operatorname{rk}1510\),应该上不了多少分. 只切了 \(\texttt{A,B,C,D}\) 四题. A - Ge ...

  3. AtCoder Beginner Contest 255(E-F)

    Aising Programming Contest 2022(AtCoder Beginner Contest 255) - AtCoder E - Lucky Numbers 题意: 给两个数组a ...

  4. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  5. AtCoder Beginner Contest 184 题解

    AtCoder Beginner Contest 184 题解 目录 AtCoder Beginner Contest 184 题解 A - Determinant B - Quizzes C - S ...

  6. atcoder beginner contest 251(D-E)

    Tasks - Panasonic Programming Contest 2022(AtCoder Beginner Contest 251)\ D - At Most 3 (Contestant ...

  7. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  8. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  9. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  10. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

随机推荐

  1. Java中YYYY-MM-dd在跨年时出现的bug

    先看一张图: Bug的产生原因: 日期格式化时候,把 yyyy-MM-dd 写成了 YYYY-MM-dd Bug分析: 当时间是2019-08-31时, public class DateTest { ...

  2. @RequestBody中使用@DateTimeFormat报错:JSON parse error: Expected array or string.; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException

    原因分析 根据异常提示:不匹配输入异常,指输入的参数错误,说是只支持String类型和Array数组类型的. @PostMapping("/test") public Dto ge ...

  3. 如何在 Linux 上使用 NPOI

    由于 NPOI 使用 System.Drawing.Common,因此在 Linux 系统上必须安装 libgdiplus 和 libc6. Ubuntu 16.04+ apt-get install ...

  4. 【深度学习项目二】卷积神经网络LeNet实现minst数字识别

    相关文章: [深度学习项目一]全连接神经网络实现mnist数字识别 [深度学习项目二]卷积神经网络LeNet实现minst数字识别 [深度学习项目三]ResNet50多分类任务[十二生肖分类] 『深度 ...

  5. 验证码识别服务2Captcha框架

    2Captcha是一个自动验证码识别服务,主要用于解决各种互联网服务中的验证码问题.在许多网站注册账户或进行敏感操作时,为了验证用户是真实的而不是自动化程序,会出现验证码.用户必须正确输入验证码,才能 ...

  6. grafana+prometheus+loki的使用

    grafana官网:https://grafana.com/zh-cn/grafana/ grafana下载:https://grafana.com/grafana/download?pg=graf& ...

  7. vue2-ace-editor代码编辑器使用

    安装 npm安装 npm install --save-dev vue2-ace-editor 如果需要拷贝到内网,需要 npm安装后 将 vue2-ace-editor 和 brace( vue2- ...

  8. Docker从认识到实践再到底层原理(五)|Docker镜像

    前言 那么这里博主先安利一些干货满满的专栏了! 首先是博主的高质量博客的汇总,这个专栏里面的博客,都是博主最最用心写的一部分,干货满满,希望对大家有帮助. 高质量博客汇总 然后就是博主最近最花时间的一 ...

  9. 教你用JavaScript实现搜索展开

    欢迎来的我的小院,恭喜你今天又要涨知识了! 案例内容 利用JavaScript实现搜索框的移动展开. 演示 学习 <!DOCTYPE html> <html lang="e ...

  10. 域名解析迟迟不生效,刷新本地DNS的方法

    ipconfig /flushdns 刷新后,再ping  发生域名解析 的指向就对了.!