1 题目描述(题目链接)
2 题解
由题意得, n a = m + c − b na=m+c-b na=m+c−b,则 n a ∈ [ m + l − r , m + r − l ] na\in [m+l-r,m+r-l] na∈[m+l−r,m+r−l]。对于 a ∈ [ l , r ] a\in [l,r] a∈[l,r],遍历求解 n = ⌊ m + r − l a ⌋ n=\lfloor \cfrac{m+r-l}{a} \rfloor n=⌊am+r−l⌋,并验证 n ∗ a n*a n∗a是否在上述范围内,如果在,则 b , c b,c b,c的值只需要满足 c − b = n a − m c-b = na-m c−b=na−m即可。
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
int main(int argc, const char * argv[]) {
// insert code here...
int t;
cin>>t;
ll l[20], r[20], m[20];
ll i, a, n;
ll left, right;
for (i = 0; i < t; i++){
cin>>l[i]>>r[i]>>m[i];
}
for (i = 0; i < t; i++){
left = l[i] - r[i] + m[i];
right = r[i] - l[i] + m[i];
for (a = l[i]; a <= r[i]; a++){
n = floor(right/a);
if (left <= a*n && a*n <= right){
break;
}
}
if (a*n - m[i] < 0)
cout<<a<<" "<<r[i]<<" "<<r[i]+a*n-m[i]<<endl;
else
cout<<a<<" "<<r[i]+m[i]-a*n<<" "<<r[i]<<endl;
}
return 0;
}
t = int(input())
l, r, m = [], [], []
for i in range(t):
lrm = input().split()
l.append(int(lrm[0]))
r.append(int(lrm[1]))
m.append(int(lrm[2]))
for i in range(t):
left = m[i] + l[i] - r[i]
right = m[i] + r[i] - l[i]
for a in range(l[i], r[i] + 1):
n = right//a
if left <= a*n <= right:
break
if a*n < m[i]:
print(a, r[i], r[i]+a*n-m[i], end=" ")
else:
print(a, r[i]+m[i]-a*n, r[i], end=" ")