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 ...
随机推荐
- SAAS云平台搭建札记: (三) AntDesign + .Net Core WebAPI权限控制、动态菜单的生成
我们知道,当下最火的前端框架,非蚂蚁金服的AntDesign莫属,这个框架不仅在国内非常有名,在国外GitHub上React前端框架也排名第一.而且这个框架涵盖了React.Vue.Angular等多 ...
- 服务器报错"您的主机中的软件中止了一个已建立的连接"
网上很多的说法都模棱两可,只是说和远程连接有关,这个说的太泛泛了. 我现在遇到的问题是java web出现的, 执行表单提交的时候出现该错误,原因是ajax和表单同时提交导致的, 相信很多朋友用了aj ...
- Spring AOP之多切面运行顺序
多切面运行顺序 当一个方法的执行被多个切面共同切的时候,环绕通知只影响当前切面的通知顺序,例如创建两个切面logUtil,validateUtil两个切面共同监视计算器类的加法运算,add(int a ...
- Js中函数式编程的理解
函数式编程的理解 函数式编程是一种编程范式,可以理解为是利用函数把运算过程封装起来,通过组合各种函数来计算结果.函数式编程与命令式编程最大的不同其实在于,函数式编程关心数据的映射,命令式编程关心解决问 ...
- python学习笔记 | 国内常用源镜像地址
各镜像列表 清华:https://pypi.tuna.tsinghua.edu.cn/simple 阿里云:http://mirrors.aliyun.com/pypi/simple/ 中国科技大学 ...
- 给mysql选择调度策略
在gun/linux上,队列调度决定了到块设备的请求实际上发送到底层设置的顺序.默认情况下是cfg(完全公平排队)策略,随意使用的笔记本和台式机使用中个调度策略没有问题,并且有助于防止io饥饿,但是用 ...
- 【Linux】ntp的一些坑。你肯定遇到过
ntpdate提示 19 Jan 10:33:11 ntpdate[29616]: no server suitable for synchronization found 这种问题从下面几个点开始验 ...
- React中的合成事件
React中的合成事件 React自己实现了一套高效的事件注册.存储.分发和重用逻辑,在DOM事件体系基础上做了很大改进,减少了内存消耗,简化了事件逻辑,并最大程度地解决了IE等浏览器的不兼容问题. ...
- 代码页(CodePage)列表
代码页编号 国家地区或语言37 IBM037 IBM EBCDIC (US-Canada) 437 IBM437 ...
- Java安全之Weblogic 2018-3248分析
Java安全之Weblogic 2018-3248分析 0x00 前言 基于前面的分析,后面的还是主要看补丁的绕过方式,这里就来简单的记录一下. 0x01 补丁分析 先来看看补丁细节 private ...