Three Integers CodeForces - 1311D(思维+暴力)
You are given three integers a≤b≤c.
In one move, you can add +1 or ?1 to any of these integers (i.e. 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 A≤B≤C such that B is divisible by A and C is divisible by B.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1≤t≤100) — 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 a,b and c (1≤a≤b≤c≤104).
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 A≤B≤C such that B is divisible by A and C is divisible by B. On the second line print any suitable triple A,B and C.
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
思路:因為ABC都是10000以內(nèi)的數(shù)字。按照題意操作之后會有b=k1* a,c=k2 * b=k1 * k2* a。b和c都不會太大,2e4內(nèi)絕對是沒問題的,這樣我們就枚舉a和k1,k2,這樣就大大的縮短了時間。不會有100001000010000這樣的時間復(fù)雜度。
代碼如下:
努力加油a啊,(o)/~
總結(jié)
以上是生活随笔為你收集整理的Three Integers CodeForces - 1311D(思维+暴力)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Perform the Combo Co
- 下一篇: 凶手(思维)