思路
题目要求:
\[na+b-c=m \]
我们可以转换为
\[na-m=c-b \]
然后\(c-b\)是固定不变的,我们去枚举a,在枚举的a的时候我们发现要使等式尽可能的成立只有让\(na-m\)的差值绝对值越小越好,然后我们会发现\(na\)在\(m\)的左右两侧时,差值绝对值最小。
比如说
\[2*a……m……3*a \]
我们让m将在他们中间,此时的差值绝对值是最小的。
然后枚举\(a\)即可。
其中求解左边系数时只有当\(i<m\)才会有左边的系数。
因为当\(i\geq m\)时,此时\(n\)无论取何止都是在\(m\)的右侧。
所以我们要分开讨论。
\(|m\%i|\)就是左边的差值,\(|a-m\%i|\)就是右边的差值。然后找最小的可能。
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define DOF 0x7f7f7f7f
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define debug(case,x); cout<<case<<" : "<<x<<endl;
#define open freopen("ii.txt","r",stdin)
#define close freopen("oo.txt","w",stdout)
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
using namespace std;
//#define int long long
#define lson rt<<1
#define rson rt<<1|1
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> PII;
const int maxn = 1e6 + 10;
void solve() {
ll l,r,m;cin>>l>>r>>m;
ll lf=l-r,rf=r-l;
for(int i=l;i<=r;++i){
if(m>i){
if(m%i<=rf){
cout<<i<<" "<<l+m%i<<" "<<l<<endl;break;
}else if(i-m%i<=rf){
cout<<i<<" "<<r-(i-m%i)<<" "<<r<<endl;break;
}
}else if(i>=m&&i-m<=rf){
cout<<i<<" "<<r-i+m<<" "<<r<<endl;
break;
}
}
}
int main() {
int __;
cin >> __;
// scanf("%d",&__);
while(__--) {
solve();
}
}
B. Dubious Cyrpto
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer n, he encrypts it in the following way: he picks three integers a, b and c such that l≤a,b,c≤r, and then he computes the encrypted value m=n⋅a+b−c.
Unfortunately, an adversary intercepted the values l, r and m. Is it possible to recover the original values of a, b and c from this information? More formally, you are asked to find any values of a, b and c such that
a, b and c are integers,
l≤a,b,c≤r,
there exists a strictly positive integer n, such that n⋅a+b−c=m.
Input
The first line contains the only integer t (1≤t≤20) — the number of test cases. The following t lines describe one test case each.
Each test case consists of three integers l, r and m (1≤l≤r≤500000, 1≤m≤1010). The numbers are such that the answer to the problem exists.
Output
For each test case output three integers a, b and c such that, l≤a,b,c≤r and there exists a strictly positive integer n such that n⋅a+b−c=m. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions.