D. Three Integers

链接: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&nbs***bsp;−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; 
	 		
	 	}
	 	
		  
	 }
}

 

全部评论

相关推荐

09-16 14:33
已编辑
南京大学 Java
最近福耀科技大学好火啊,号称保底25w年薪就业,有不少高分学生都报了,兄弟们你有这个分,报传统92还是它?
ITTM:如果真的像宣传所说的能给到25w保底薪资,985也没啥吸引力了,这年头,读书不就是为了能多赚点钱嘛
点赞 评论 收藏
分享
昨天 17:59
门头沟学院 Java
点赞 评论 收藏
分享
秋招投简历提醒助手:一开始还觉得是正常交流。直到一看薪资4-6😨
点赞 评论 收藏
分享
09-18 14:30
门头沟学院 Java
mountisome:去骗吃骗喝是吧,学到了
我的秋招日记
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务