codeforce 1311 D. Three Integers(暴力 + 剪枝)

D. Three Integers

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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

题意:

给出3个正整数,每次操作只能对某个数+1或-1,问至少操作多少次可以得到A < B < C ,B能被A整除,C能被B整除。

 

1 <= a, b, c <= 10000, 枚举 + 剪枝

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int N = 2e5 + 10;

int main()
{
    int t, a, b, c;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d%d%d", &a, &b, &c);
        int ans = inf;
        int A, B, C;
        for(int i = 1; i <= 15000; ++i)
        {
            for(int j = i; j <= 15000; j += i)
            {
                for(int k = j; k <= 15000; k += j)
                {
                    int tmp = abs(a - i) + abs(b - j) + abs(c - k);
                    if(ans > tmp)
                    {
                        ans = tmp;
                        A = i;
                        B = j;
                        C = k;
                    }
                }
            }
        }
        cout<<ans<<'\n';
        cout<<A<<' '<<B<<' '<<C<<'\n';
    }
    return 0;
}

 

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 春招至今,你的战绩如何? #
6678次浏览 64人参与
# 你的实习产出是真实的还是包装的? #
1331次浏览 32人参与
# 巨人网络春招 #
11223次浏览 223人参与
# 军工所铁饭碗 vs 互联网高薪资,你会选谁 #
7120次浏览 37人参与
# 简历第一个项目做什么 #
31334次浏览 315人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
186557次浏览 1115人参与
# 米连集团26产品管培生项目 #
4806次浏览 206人参与
# 研究所笔面经互助 #
118794次浏览 577人参与
# 面试紧张时你会有什么表现? #
30416次浏览 188人参与
# 简历中的项目经历要怎么写? #
309597次浏览 4167人参与
# 职能管理面试记录 #
10726次浏览 59人参与
# AI时代,哪些岗位最容易被淘汰 #
62775次浏览 750人参与
# 网易游戏笔试 #
6382次浏览 83人参与
# 把自己当AI,现在最消耗你token的问题是什么? #
7014次浏览 154人参与
# 腾讯音乐求职进展汇总 #
160447次浏览 1107人参与
# 从哪些方向判断这个offer值不值得去? #
56712次浏览 357人参与
# 正在春招的你,也参与了去年秋招吗? #
362761次浏览 2632人参与
# 你怎么看待AI面试 #
179447次浏览 1184人参与
# 小红书求职进展汇总 #
226916次浏览 1357人参与
# 你的房租占工资的比例是多少? #
92153次浏览 896人参与
# 校招笔试 #
467856次浏览 2955人参与
# 经纬恒润求职进展汇总 #
155724次浏览 1085人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务