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 ...
随机推荐
- 微信小程序-Storage
官方文档地址:https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.setStorageSync.html ?> Sto ...
- C/C++ 类与构造析构等知识
简单定义类 #include <iostream> #include <string> using namespace std; class Student { public: ...
- 监控Celery不一定非要使用Flower
运维平台中有许多的周期/定时/异步任务,例如证书扫描.数据备份.日志清理.线上作业等等,这些任务的执行都是借助于Celery来完成的.任务多了之后就会遇到一系列的问题,例如我之前写过的将任务分多队列来 ...
- 使用s3fs-fuse挂载minio文件时无法删除问题排查过程
使用s3fs-fuse挂载minio文件时无法删除问题排查过程 结论:部分场景无法满足,具体问题详见正文 1. 部署minio docker run -p 9000:9100 -p 909 ...
- (python)做题记录||2024.2.4||题目是codewars的【 All Balanced Parentheses】
题目链接:https://www.codewars.com/kata/5426d7a2c2c7784365000783/python 我的解决方案: def balanced_parens(n): # ...
- 域名解析迟迟不生效,刷新本地DNS的方法
ipconfig /flushdns 刷新后,再ping 发生域名解析 的指向就对了.!
- Android里使用AspectJ实现AOP
前言 Aspectj提供一种在字符串里编程的模式,即在字符串里写函数,然后程序启动的时候会动态的把字符串里的函数给执行了. 例如: "execution(* *(..))" 这里 ...
- win32--GetFileAttributes
DWORD d = GetFileAttributes(path.c_str()); 根据返回的十进制,对比文件属性,来检索指定文件或目录的文件系统属性. 也可以使用 if ((d & FIL ...
- win32 - WaitForMultipleObjects的使用
创建5个线程,并无限期地打印某些内容 #include <Windows.h> #include <stdio.h> DWORD IDs[5]; DWORD WINAPI Th ...
- 【Android 逆向】【攻防世界】android2.0
这是一道纯算法还原题 1. apk安装到手机,提示输入flag,看来输入就是flag 2. jadx 打开apk查看 this.button.setOnClickListener(new View.O ...