codeforce 1311 D. Three Integers
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的更多相关文章
- 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 ...
- F. Moving Points 解析(思維、離散化、BIT、前綴和)
Codeforce 1311 F. Moving Points 解析(思維.離散化.BIT.前綴和) 今天我們來看看CF1311F 題目連結 題目 略,請直接看原題. 前言 最近寫1900的題目更容易 ...
- 解题报告:codeforce 7C Line
codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...
- Two progressions CodeForce 125D 思维题
An arithmetic progression is such a non-empty sequence of numbers where the difference between any t ...
- 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 ...
- CodeForce 192D Demonstration
In the capital city of Berland, Bertown, demonstrations are against the recent election of the King ...
- 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 ...
- CodeForce 222C Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractio ...
- CodeForce 359C Prime Number
Prime Number CodeForces - 359C Simon has a prime number x and an array of non-negative integers a1, ...
随机推荐
- Hadoop(十):本地IDEA链接远程Hadoop
本文使用的Hadoop为2.7.7,版本如果不同要下载相应版本的文件 配置本地的Hadoop库(不需完整安装,但是要有环境支持) 下载文件 https://github.com/speedAngel/ ...
- matplotlib formatters
Tick formatting is controlled by classes derived from Formatter. The formatteroperates on a single ...
- 墨者学院靶场:uWSGI(CVE-2018-7490)路径遍历漏洞复现
0x01漏洞简介 uWSGI是一款Web应用程序服务器,它实现了WSGI.uwsgi和http等协议.uWSGI 2.0.17之前版本中存在路径遍历漏洞,该漏洞源于程序没有正确的处理DOCUMENT_ ...
- openwrite使用说明
访问官网https://openwrite.cn/注册登录 访问https://openwrite.cn/plugin-chrome/ 下载插件和安装插件"OpenWrite助手1.1.4& ...
- JS生成随机颜色(rgb)
/*随机获取颜色*/ function getRandomColor() { var r = Math.floor(Math.random() * 256); var g = Math.floor(M ...
- AJ学IOS 之微博项目实战(6)导航控制器NavigationController 的滑动回退功能实现
AJ分享,必须精品 一:效果 第二篇里面写了怎样自定义navigation实现自定义的导航控制器左右按钮样式,但是当我们自己实现后,系统自带的向右边滑动来实现回退的功能就不能用了. 这里主要实现滑动回 ...
- PDF阅读器
1.SumatraPDF 非常小巧,打开很轻快 2.PDF Reader by Xodo window商店中可以找到,很好用 3. PDFXChange Editor这是我迄今为止见过的最好的PDF编 ...
- . Number throry
steve 学完了快速幂,现在会他快速的计算:(ij)%d , Alex 作为一个数学大师,给了 steve 一个问题:已知i∈[1,n],j∈[1,m] ,计算满足 (ij)%d=0 的 (i,j) ...
- xshell下使用vim的编辑一个文件Ctrl+S和Ctrl+Q
xshell下使用vim的编辑一个文件,保存的时候习惯性的按了Ctrl+S 结构悲剧了.屏幕锁死了.按其他键都没有反应,exc也不行. 经过问度娘才知道. 原来Ctrl+S在Linux里,是锁定屏幕的 ...
- Python 代码编辑器怎么选?PyCharm、VS Code、Jupyter Notebook 都各有特色
Python 代码编辑器怎么选?PyCharm.VS Code.Jupyter Notebook 都各有特色,Jupyter 适合做数据分析这些需要可视化的操作,PyCharm 更适合做完整的 Pyt ...