ayit609第七周训练e题

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 AA and 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

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

Sponsor

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        int f=9999999;
        int i,j,k,r,r1,r2,r3;
        for(i=1; i<=10000; i++)
        {
            for(j=1; j*i<=20000; j++)
            {
                for(k=1; i*j*k<=20000; k++)
                {
                    r=abs(a-i)+abs(i*j-b)+abs(i*j*k-c);
                    if(f>r)
                    {
                        f=r;
                        r1=i;
                        r2=i*j;
                        r3=i*j*k;
                    }

                }
            }
        }
       printf("%d\n",f);
       printf("%d %d %d\n",r1,r2,r3);
    }
    return 0;
}

题意

每次加1或减1使B能被A整除,C能被B整除,输出(加1或减1)次数的最小数目以及经过操作改变后的A,B,C的值。

思路  B=n* A,C=n1* B(也=n1* n* A),题目所给数据不是特别大即 1 ≤ a ≤ b ≤ c ≤ 10^4,可以暴力三层for循环

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值