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

inputCopy

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

outputCopy

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;
const long long maxn = 1e15 + 5;
int main()
{
int t;
cin >> t;
while (t--)
{
long long a, b, c, a1, b1, c1;
scanf("%lld %lld %lld", &a, &b, &c);
long long cnt = maxn;
for (long long k = 1; k <=5*c; k++)
{
for (long long i = 1; i*k<=5*c; i++)
for (long long j = 1;i*k* j <=5*c ; j++)
{ long long temp = abs(k - a) + abs(i * k - b) + abs(j * i * k - c);
if (temp < cnt)
{
cnt = temp;
a1 = k;
b1 = i * k;
c1 = i * j * k;
}
// else
// break;
}
}
printf("%lld\n", cnt);
printf("%lld %lld %lld\n", a1, b1, c1);
}
}

codeforce 1311 D. Three Integers的更多相关文章

  1. codeforce 1311 C. Perform the Combo 前缀和

    You want to perform the combo on your opponent in one popular fighting game. The combo is the string ...

  2. F. Moving Points 解析(思維、離散化、BIT、前綴和)

    Codeforce 1311 F. Moving Points 解析(思維.離散化.BIT.前綴和) 今天我們來看看CF1311F 題目連結 題目 略,請直接看原題. 前言 最近寫1900的題目更容易 ...

  3. 解题报告:codeforce 7C Line

    codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...

  4. Two progressions CodeForce 125D 思维题

    An arithmetic progression is such a non-empty sequence of numbers where the difference between any t ...

  5. CodeForce 577B Modulo Sum

    You are given a sequence of numbers a1, a2, ..., an, and a number m. Check if it is possible to choo ...

  6. CodeForce 192D Demonstration

    In the capital city of Berland, Bertown, demonstrations are against the recent election of the King ...

  7. CodeForce 176C Playing with Superglue

    Two players play a game. The game is played on a rectangular board with n × m squares. At the beginn ...

  8. CodeForce 222C Reducing Fractions

    To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractio ...

  9. CodeForce 359C Prime Number

    Prime Number CodeForces - 359C Simon has a prime number x and an array of non-negative integers a1,  ...

随机推荐

  1. MySQL入门,第四部分,学会创建、删除表

    一.列完整性约束 列完整性约束:是指对某一列设置的约束条件.该列上的数据必须满足.最常见的有: NOT NULL 该列值不能为空 NULL  该列值可以为空 UNIQUE 该列值不能存在相同 DEFA ...

  2. Linux(Fedora)系统下配制8086汇编环境

    1.到www,nasm.us下载nasm 2.解压并安装nasm #tar -xzvf nasm-2.11.08.tar.gz #cd nasm-2.11.08 #./configure #make ...

  3. javascript入门 之 zTree(十三 移动/复制事件)

    <!DOCTYPE html> <HTML> <HEAD> <TITLE> ZTREE DEMO - copyNode / moveNode</T ...

  4. 安卓开发学习日记 DAY4——Button,ImageButton

    Button与ImageButton基本类似 也有类似于TextView和ImageView的区别 这里需要注意的是: 在你定义text属性的内容时,最好是在Values文件下的String.xml中 ...

  5. Jquery的$.get(),$.post(),$.ajax(),$.getJSON()用法详细解读

    1.$.get $.get()方法使用GET方式来进行异步请求,它的语法结构为: $.get( url [, data] [, callback] ) 解释一下这个函数的各个参数: url:strin ...

  6. Mysql基础知识一

    1.数据库的定义 数据:描述事物符号记录.(包括数字.文字.图形.图像.声音.档案记录等)以记录形式统一的格式进行存储. 广义上的数据:出现在计算机内部的一切二进制数据流都为数据 狭义上的数据:只是数 ...

  7. C语言小练习之学生信息管理系统

    C语言小练习之学生信息管理系统 main.c文件   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2 ...

  8. java nio消息半包、粘包解决方案

    问题背景 NIO是面向缓冲区进行通信的,不是面向流的.我们都知道,既然是缓冲区,那它一定存在一个固定大小.这样一来通常会遇到两个问题: 消息粘包:当缓冲区足够大,由于网络不稳定种种原因,可能会有多条消 ...

  9. for循环,for…in循环,forEach循环的区别

    for循环,for…in循环,forEach循环的区别for循环通关for循环,生成所有的索引下标for(var i = 0 ; i <= arr.length-1 ; i++){ 程序内容 } ...

  10. 第十节:xml、re、logging模块

    XML模块:(用到的时候再看)tree=xml.parse('xmltest.xml')root= tree.getroot()print(root.tag) 打印对象的标签root.attrib 获 ...