D. Three Integers
You are given three integers .
In one move, you can add or to any of these integers ( . increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations.
You have to perform the minimum number of such operations in order to obtain three integers such that is divisible by and C is divisible by .
You have to answer t independent test cases.
Input
The first line of the input contains one integer — the number of test cases.
The next t lines describe test cases. Each test case is given on a separate line as three space-separated integers and
Output
For each test case, print the answer. In the first line print res — the minimum number of operations you have to perform to obtain three integers such that is divisible by and is divisible by . On the second line print any suitable triple and .
Example
input
8
1 2 3
123 321 456
5 10 15
15 18 21
100 100 101
1 22 29
3 19 38
6 30 46
output
1
1 1 3
102
114 228 456
4
4 8 16
6
18 18 18
1
100 100 100
7
1 22 22
2
1 19 38
8
6 24 48
解题思路:
给了
三个数,现在你可以对任意一个数进行任意次数的
和
问你最少操作次数 让
那
改变的最大范围也就是
,直接枚举就可以,但是
是会超时的。这里稍微优化一下。
AC代码:
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int N = 2e5 + 10;
int t;
int n, m;
int res, len, pre, now;
int a, b, c;
ll ans;
int a1, a2, a3;
int main()
{
sd(t);
while (t--)
{
sddd(a, b, c);
ans = INF;
rep(i, 1, 11000)
{
for (int j = 1; i * j <= 11000; j++)
{
for (int k = 1; i * j * k <= 11000; k++)
{
if (ans > abs(i - a) + abs(i * j - b) + abs(i * j * k - c))
{
ans = abs(i - a) + abs(i * j - b) + abs(i * j * k - c);
a1 = i, a2 = i * j, a3 = i * j * k;
}
}
}
}
pld(ans);
cout << a1 << ' ' << a2 << ' ' << a3 << '\n';
}
return 0;
}