D. Three Integers

妖精的绣舞 提交于 2020-02-26 02:24:56

链接:https://codeforces.ml/contest/1311/problem/D

You are given three integers a≤b≤ca≤b≤c.

In one move, you can add +1+1 or −1−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≤CA≤B≤C such that BB is divisible by AAand CC is divisible by BB.

You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases.

The next tt lines describe test cases. Each test case is given on a separate line as three space-separated integers a,ba,b and cc (1≤a≤b≤c≤1041≤a≤b≤c≤104).

Output

For each test case, print the answer. In the first line print resres — the minimum number of operations you have to perform to obtain three integers A≤B≤CA≤B≤C such that BB is divisible by AA and CC is divisible by BB. On the second line print any suitable triple A,BA,B and CC.

Example

input

Copy

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

Copy

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

代码:

#include<bits/stdc++.h>
using namespace std;
long long n,m,t,l,ans,flag,a1,b1,c1,s;
long long a,b,c;
int main()
{
	 cin>>t;
	 while(t--)
	 {
	 	cin>>a>>b>>c;
	 	if(b%a==0&&c%b==0)
	 	{
	 		cout<<0<<endl;
	 		cout<<a<<" "<<b<<" "<<c<<endl;
	 	}
	 	else
	 	{
	 		s=1e9+7;
	 		for(int i=1;i<=10001;i++)
	 		{
	 			for(int j=i;j<=20002;j+=i)
	 			{
	 				for(int k=j;k<=40004;k+=j)
	 				{
	 					if(abs(i-a)+abs(j-b)+abs(k-c)<s)
	 					{
	 						s=abs(i-a)+abs(j-b)+abs(k-c);
	 						a1=i;
	 						b1=j;
							c1=k;
	 					}
	 				}
	 			}
	 		}
	 		cout<<s<<endl;
	 		cout<<a1<<" "<<b1<<" "<<c1<<endl; 
	 		
	 	}
	 	
		  
	 }
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!