D. Three Integers
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given three integersa≤b≤c.

In one move, you can add+1or−1toanyof 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 integersA≤B≤Csuch thatBis divisible byAandCis divisible byB.

You have to answertindependent test cases.

Input
The first line of the input contains one integert (1≤t≤100) — the number of test cases.

The nexttlines describe test cases.Each test case is given on a separate line as three space-separated integersa,bandc (1≤a≤b≤c≤104).

Output
For each test case, print the answer.In the first line printres— the minimum number of operations you have to perform to obtain three integersA≤B≤Csuch thatBis divisible byAandCis divisible byB.On the second line printanysuitable tripleA,BandC.

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

bb=c即可

``````#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define me(a,x) memset(a,x,sizeof a)
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define all(x) (x).begin(), (x).end()
#define pb(a) push_back(a)
#define paii pair<int,int>
#define pali pair<ll,int>
#define pail pair<int,ll>
#define pall pair<ll,ll>
#define fi first
#define se second
vector<int>g[20005];
int a,b,c;
void inist()
{
for(int i=1;i<=20000;i++)
{
for(int j=1;j<=20000/i;j++)
g[i*j].pb(i);
}

}
int work(int& aa,int bb,int& cc)
{
int ans=0;
int minn=1000000;
int l=g[bb].size();
int x=aa;
for(int i=0;i<l;i++)
{
if(minn>abs(g[bb][i]-aa))
{
minn=abs(g[bb][i]-aa);
x=g[bb][i];
}
}
aa=x;
ans+=minn;
if(bb>cc)
{
ans+=abs(bb-cc);
cc=bb;
}
if(cc%bb<bb-cc%bb)
{
ans+=cc%bb;
cc-=cc%bb;
}
else
{
ans+=bb-cc%bb;
cc+=bb-cc%bb;
}
return ans;
}
int main()
{
inist();
int t;
cin>>t;
while(t--)
{
int ans=100000;
int ansa,ansb,ansc;
cin>>a>>b>>c;
for(int i=1;i<=20000;i++)
{
int a1=a,b1=i,c1=c;
int temp=abs(i-b);
temp+=work(a1,b1,c1);
if(temp<ans)
{
ans=temp;
ansa=a1;ansb=b1;ansc=c1;
}
}
cout<<ans<<endl;
cout<<ansa<<" "<<ansb<<" "<<ansc<<endl;
}
return 0;
}

``````