题目链接: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(数论)的更多相关文章

  1. Codeforces Round #657 (Div. 2) C. Choosing flowers(贪心)

    题目链接:https://codeforces.com/contest/1379/problem/C 题意 有 $m$ 种花,每种花数量无限,第一次购买一种花收益为 $a_i$,之后每一次购买收益为 ...

  2. Codeforces Round #657 (Div. 2) A. Acacius and String(字符串)

    题目链接:https://codeforces.com/contest/1379/problem/A 题意 给出一个由 '?' 和小写字母组成的字符串,可以将 '?' 替换为小写字母,判断是否存在一种 ...

  3. Codeforces Round #276 (Div. 2)A. Factory(数论)

    这道题可以暴力的一直按要求的方法去做,做1000000次还不能整除m就认为永远不能整除m了(m不超过100000,循环1000000次比较安全了已经).这种方法可以AC. 下面深入的分析一下到底循环多 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #275 (Div. 2) A. Counterexample【数论/最大公约数】

    A. Counterexample time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. 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 ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. php利用腾讯ip分享计划获取地理位置示例分享

    <?php function getIPLoc_QQ($queryIP){ $url = 'http://ip.qq.com/cgi-bin/searchip?searchip1='.$quer ...

  2. 【Java基础】Eclipse 和数组

    Eclipse 和数组 Eclipse 安装和使用 ... 数组的概述 数组(Array):是多个相同类型数据按一定顺序排列的集合,并使用一个名字命名,并通过编号的方式对这些数据进行统一管理. 数组相 ...

  3. 【ORA】ORA-39002,ORA-39070,ORA-29283, ORA-06512,ORA-29283解决办法

    今天使用IMPDP导入的时候报了一个错误 ORA-39002: invalid operation  ORA-39070: Unable to open the log file.  ORA-2928 ...

  4. os-hackos-3-docker提权

    0x00 cewl http://192.168.43.179/websec/爬取页面所有的单词做成字典 hydra -l contact@hacknos.com -P cewl.txt 192.16 ...

  5. three.js cannon.js物理引擎之约束

    今天郭先生继续说cannon.js,主演内容就是点对点约束和2D坐标转3D坐标.仍然以一个案例为例,场景由一个地面.若干网格组成的约束体和一些拥有初速度的球体组成,如下图.线案例请点击博客原文. 下面 ...

  6. SAP表的锁定与解锁

    表的锁定模式有三种模式. lock mode有三种模式:分别是S,E,X.含义如下:     S (Shared lock, read lock)     E (Exclusive lock, wri ...

  7. [Usaco 2012 Feb]Nearby Cows

    题目描述 FJ发现他的牛经常跑到附近的草地去吃草,FJ准备给每个草地种足够的草供这个草地以及附近草地的奶牛来吃.FJ有N个草地(1<=N<=100000),有N-1条双向道路连接这些草地, ...

  8. Sklearn 与 TensorFlow 机器学习实战—一个完整的机器学习项目

    本章中,你会假装作为被一家地产公司刚刚雇佣的数据科学家,完整地学习一个案例项目.下面是主要步骤: 项目概述. 获取数据. 发现并可视化数据,发现规律. 为机器学习算法准备数据. 选择模型,进行训练. ...

  9. AOP面向切面编程(使用注解和使用配置文件)

    Aop(面向切面编程) 使用注解的方式: 加入相应的jar包: com.springsource.org.aopalliance-1.0.0.jar com.springsource.org.aspe ...

  10. Linux安装MYSQL并部署主从复制集群

    主节点部署 安装数据库 Ubuntu apt-get install mysql-server -y systemctl start mysql systemctl enabled mysql Cen ...