Codeforces Round #657 (Div. 2) B. Dubious Cyrpto(数论)
题目链接:https://codeforces.com/contest/1379/problem/B
题意
给出三个正整数 $l,r,m$,判断在区间 $[l,r]$ 内是否有 $a,b,c$ 满足存在正整数 $n$,使得 $n \cdot a + b - c = m$ 。
题解
最容易想的一种情况是:
\begin{equation} {\lfloor \frac{m}{a} \rfloor} \cdot a + m\ \%\ a = m \end{equation}
令 $b = l + m\ \%\ a,\ c = l$ 即可。
但是当 $m<a$ 时,${\lfloor \frac{m}{a} \rfloor} = n = 0$,不满足 $n$ 为正整数的要求,或者 $m\ \%\ a$ 较大,超出了 $[l,r]$ 区间,此时可以将原式变换为:
\begin{equation} {\lfloor \frac{m}{a} \rfloor} \cdot a + a - (a - m\ \%\ a) = m \nonumber \end{equation}
即,
\begin{equation} ({\lfloor \frac{m}{a} \rfloor} + 1) \cdot a - (a - m\ \%\ a) = m \end{equation}
因为是减去一个数,为了尽量不超出区间,令 $b = r - (a - m\ \%\ a),\ c = r$,并且此时 $n$ 一定 $\ge 1$ 。
代码
#include <bits/stdc++.h>
using ll = long long;
using namespace std; void solve() {
ll l, r, m; cin >> l >> r >> m;
for (ll a = l; a <= r; ++a) {
ll b = l + m % a;
ll c = l;
if (m / a > 0 and l <= b and b <= r) {
cout << a << ' ' << b << ' ' << c << "\n";
return;
}
b = r - (a - m % a);
c = r;
if (l <= b and b <= r) {
cout << a << ' ' << b << ' ' << c << "\n";
return;
}
}
} int main() {
int t; cin >> t;
while (t--) solve();
}
Codeforces Round #657 (Div. 2) B. Dubious Cyrpto(数论)的更多相关文章
- Codeforces Round #657 (Div. 2) C. Choosing flowers(贪心)
题目链接:https://codeforces.com/contest/1379/problem/C 题意 有 $m$ 种花,每种花数量无限,第一次购买一种花收益为 $a_i$,之后每一次购买收益为 ...
- Codeforces Round #657 (Div. 2) A. Acacius and String(字符串)
题目链接:https://codeforces.com/contest/1379/problem/A 题意 给出一个由 '?' 和小写字母组成的字符串,可以将 '?' 替换为小写字母,判断是否存在一种 ...
- Codeforces Round #276 (Div. 2)A. Factory(数论)
这道题可以暴力的一直按要求的方法去做,做1000000次还不能整除m就认为永远不能整除m了(m不超过100000,循环1000000次比较安全了已经).这种方法可以AC. 下面深入的分析一下到底循环多 ...
- Codeforces Round #305 (Div. 2) E题(数论+容斥原理)
E. Mike and Foam time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- Codeforces Round #305 (Div. 2) C题 (数论)
C. Mike and Frog time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #599 (Div. 1) A. Tile Painting 数论
C. Tile Painting Ujan has been lazy lately, but now has decided to bring his yard to good shape. Fir ...
- Codeforces Round #275 (Div. 2) A. Counterexample【数论/最大公约数】
A. Counterexample time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- vrp OS Switch Rotuer Application
交换机可以隔离冲突与,路由器可以隔离广播域,这两种设备在企业网络中应用越来越广泛.随着越来越多的终端接入到网络中,网络设备的负担也越来越重,这时网络设备可以通过华为专有的VRP系统来提升运行效率. 通 ...
- [从源码学设计]蚂蚁金服SOFARegistry 之 ChangeNotifier
[从源码学设计]蚂蚁金服SOFARegistry 之 ChangeNotifier 目录 [从源码学设计]蚂蚁金服SOFARegistry 之 ChangeNotifier 0x00 摘要 0x01 ...
- oracle数据库psu升级(本实验是将10.2.0.3.12升级到10.2.0.3.15)
psu升级(本实验是将10.2.0.3.12升级到10.2.0.3.15) 一.解压安装包自定义存放路径为/home/oracle/yjb/psu/10.2.0.3.15cd /home/oracle ...
- oracle range分区表已经有了MAXVALUE 分区,如何添加分区?要不能删除MAXVALUE分区里的数据,不影响在线应用。
来做个实验说明该问题:1.创建个分区表SQL> create table p_range_test 2 (id number,name varchar2(100)) 3 partition by ...
- python函数1-函数基础
- 原生工程接入Flutter实现混编
前言 上半年我定的OKR目标是帮助团队将App切入Flutter,实现统一技术栈,变革成多端融合开发模式.Flutter目前是跨平台方案中最有潜力实现我们这个目标的,不管是Hybird还是React ...
- SAP中的密码输入框
在SAP中的密码输入框,可分为两种情况: 1.用selection语句书写的选择屏幕上的密码输入框 实现的方式就是在AT SELECTION-SCREEN OUTPUT事件中写入如下代码: LOOP ...
- Flask之路由系统
路由系统 路由的两种写法 1.第一种方法: def index(): return render_template('index.html') app.add_url_rule('/index', ' ...
- flask文件下载
后端的代码 # coding:utf-8 from flask import Flask app = Flask(__name__) @app.route("/upload", m ...
- Docker容器日志清理方案
Docker容器在运行过程中会产生很多日志,久而久之,磁盘空间就被占满了,以下分享docker容器日志清理的几种方法 删除日志 在linux上,容器日志一般存放在 /var/lib/docker/co ...