题意:
给三个整数
a
,
b
,
c
a,b,c
a,b,c
可以对每个数进行
+
1
+1
+1或者
−
1
-1
−1任意次
使得三个数满足,
b
b
b能被
a
a
a整除,
c
c
c能被
b
b
b整除
求变化成这种关系的最小次数,并输出
a
,
b
,
c
a,b,c
a,b,c
思路:
数据只有1e4,直接暴力枚举即可
从1到1e4枚举a
然后枚举a的倍数b
然后枚举b的倍数c
T
∗
n
∗
l
o
g
(
n
)
∗
l
o
g
(
n
)
T*n*log(n)*log(n)
T∗n∗log(n)∗log(n)
代码:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
typedef long long ll;
#define Pll make_pair
#define PB push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int MAXN=2e5+50;
const int inf=0x3f3f3f3f;
const int M=10050;
int n,m,_;
void solve(){
int a,b,c,x,y,z;
int ans=inf;
scanf("%d%d%d",&a,&b,&c);
for(int i=1;i<=M;i++)
for(int j=i;j<=M;j+=i)
for(int k=j;k<=M;k+=j){
int tmp=abs(a-i)+abs(b-j)+abs(c-k);
if(ans>tmp){
ans=tmp;
x=i;
y=j;
z=k;
}
}
printf("%d\n%d %d %d\n",ans,x,y,z);
}
int main()
{
for(scanf("%d",&_);_;_--)solve();
return 0;
}