题意: 已知存在三个数a,b,c满足l <= a,b,c <= r,且m = n * a + b - c。现在告诉你l,r和m的值,需要你找到一组可行的a,b,c。
思路:
- 枚举a,令 x = m%a,n = m/a,于是x是用取模操作得到的,所以一定有x>=0
- 如果n >= 1且 x <= r-l,那么可以构造出b = x+l,c = l,因为一定是x < a的,所以就一定有x + l <= r。
- 如果x > r-l,因为b - c的范围在[l-r,r-l]之间,说明b - c是一个负数,正是因为取模操作只能得到正数,实际上x=b-c+a,多加了一个a,那么b-c = x-a,设p = x-a就判断是否有p >= l-r,如果满足则可以构造出b = r+p,c=r。这种情况不用判断n是否>=1,因为b-c多加了一个a进去。
代码实现:
#include<bits/stdc++.h>
#define endl '\n'
#define null NULL
#define ll long long
#define int long long
#define pii pair<int, int>
#define lowbit(x) (x &(-x))
#define ls(x) x<<1
#define rs(x) (x<<1+1)
#define me(ar) memset(ar, 0, sizeof ar)
#define mem(ar,num) memset(ar, num, sizeof ar)
#define rp(i, n) for(int i = 0, i < n; i ++)
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define pre(i, n, a) for(int i = n; i >= a; i --)
#define IOS ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int way[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
using namespace std;
const int inf = 0x7fffffff;
const double PI = acos(-1.0);
const double eps = 1e-6;
const ll mod = 1e9 + 7;
const int N = 2e5 + 5;
int t, l, r, m;
signed main()
{
IOS;
cin >> t;
while(t --){
cin >> l >> r >> m;
for(int a = l; a <= r; a ++){
int x = m % a;
int n = m / a;
if(n >= 1 && x <= r - l){
cout << a << " " << l + x << " " << l << endl;
break;
}
else{
x = x - a;
if(x >= l - r){ //如果abs(x) <= r-l时
cout << a << " " << r + x << " " << r << endl;
break;
}
}
}
}
return 0;
}