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 ...
随机推荐
- 【Spring】Spring JdbcTemplate
Spring JdbcTemplate 文章源码 JdbcTemplate 概述 它是 Spring 框架中提供的一个对象,是对原始 Jdbc API 对象的简单封装.Spring 框架提供了很多的操 ...
- shell 脚本安装Tomcat和java
脚本安装Tomcat和java#!/bin/bash##SCRIPT:install_jdk-8u181-linux-x64_apache-tomcat-8.0.53#AUTHOR:Shinyinfo ...
- logback为不同的包或类指定输出日志文件
对日志分割的常见需求是,需要按不同的等级进行输出,这个的配置方式类似如下,在appender节点内添加内容 <appender name="FILE-INFO" class= ...
- 【Linux】postfix大坑笔记
由于需要,想弄一个自动发送邮件的mailx或者sendmail 但是执行 echo "test" | mail -s "Worning mail !" xxxx ...
- 【Oracle LISTNER】oracle Listener 宕机解决办法
今天想起了很久没用的oracle库,用plsql尝试连接,发现报超时错误,以为是偶然,多次尝试连接,发现还是超时,于是登录到系统中,查看数据库情况,发现正常查询和修改添加,感觉不是数据库问题,查看监听 ...
- buuctf—web—Easy Calc
启动靶机,查看网页源码,发现关键字 $("#content").val() 是什么意思: 获取id为content的HTML标签元素的值,是JQuery, ("# ...
- openpose c++ 配置教程 + python api
之前有介绍过基于tensorflow的openpose版本安装,但是我觉得没有caffe框架那么好用,很多功能也实现不了,比如调节net_resolution的调节,通过调节分辨率来提高检测的精确性和 ...
- 09--Docker 安装tomcat9
1.在hub.docker.com中获取tomcat拉取地址 docker pull tomcat:9.0.41-jdk8-corretto 2.查看Dockerfile 中WORKDIR 为/use ...
- PW6513高压40V的LDO芯片,SOT89封装
一般说明 PW6513系列是一款高精度,高输入电压,低静态电流,高速,低具有高纹波抑制的线性稳压器.输入电压高达40V,负载电流为在电压=5V和VIN=7V时高达300mA.该设备采用BCD工艺制造. ...
- Flask的“中间件”
特殊装饰器 from flask import Flask,render_template,request app = Flask(__name__) @app.before_request def ...