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. Javascript 获取随机颜色的几种方式

    先认识一下颜色值的表达方式 #FFFFFF,由6位16进制数组成.#FFFFFFFF,由8位16进制数组成,前6位表示颜色,后两位数表示透明度,数值越大,透明度越小.rgb(255,255,255), ...

  2. python 入门 之 Json 序列化

    开发网站,离不了Json 但是一般情况,不支持python的其它对象,怎么办? 有办法:Json 序列化!!! 总体来说,需要序列化的数据类型为 字典,类,嵌套类. 下面是我做的一个demo,都包含了 ...

  3. 第一章 AT&T

    1.一个公司(企业)越庞大,就越危险:越复杂,就越濒临坍塌:快速发展的同时,也埋下了隐患. 2.再庞大的企业也不可能永久站立,下个十年谁也说不准谁会在浪潮之巅. 3.一个人能走多远,往往取决于他能看多 ...

  4. 22 Extends 继承(子类、父类)

    本章主要介绍继承的 概念.方法重写(@Override注解的使用).使用场景.方法的执行顺序 /*1.继承的 概念 * 继承:多个类有共同的成员变量和成员方法,抽取到另外一个类中(父类),在让多个类去 ...

  5. 7.5 this关键字的使用;标准学生类的编写 、构造方法的格式

    /** 学生类** 起名字我们要求做到见名知意.* 而我们现在的代码中的n和a就没有做到见名知意,所以我要改进.** 如果有局部变量名和成员变量名相同,在局部使用的时候,采用的是就近的原则. * 我们 ...

  6. Python设计模式(11)-状态模式

    # coding=utf-8 # *状态模式:一个方法的判断逻辑太长,就不容易修改.方法过长,其本质就是,# * 就是本类在不同条件下的状态转移.状态模式,就是将这些判断分开到各个能# * 表示当前状 ...

  7. VM卸载不完全,重装的一个下午

    玩软件就是随时面临着重新来过的危险.今天一不小心就把VM给高爆了,爆的很高的那种. 卸载不完全的VM如何在不重装系统的情况下安装. 首先第一步,肯定是通过控制面板去卸载VM,但是....但是...我靠 ...

  8. STC15W串口通信的一些梳理

    由于控制串口1进行通信移植到串口3出现了阻力,因此很有必要对串口通信进行更进一步的梳理>>>> 一 STC15W串口对应引脚: 由此我们得到四个串口引脚分别为:串口1:P3 . ...

  9. [译]HAL-超文本应用语言

    [译]HAL-超文本应用语言 精益超媒体类型 总结 HAL 是一种简单的格式,它提供了一种一致且简便的方法在 API 的资源之间进行超链接. 采用 HAL 将使您的 API 易于探索,并且其文档很容易 ...

  10. 疲劳驾驶打瞌睡?python保障您的驾驶安全

    道路千万条,安全第一条!疲劳驾驶可谓交通事故几大罪魁祸首之一,根据美国一项研究显示,司机睡眠不足4小时,交通事故肇事几率等同于醉驾. 为了减少疲劳驾驶现象,驾驶员疲劳检测应运而生.这是一项安全技术,可 ...