十分钟出思路,一小时没 AC。
#include <iostream>
using namespace std;
#define ll long long
#define int long long
#define for1(i, s, t) for (ll i(s); i<=t; ++i)
#define for2(i, t, s) for (int i(t); i>=s; --i)
#define for3(i, vec) for (auto i: vec)
#define INF 0x3f3f3f3f
#define opb pop_back
#define pb push_back
#define pf push_front
#define opf pop_front
#define fi first
#define se second
//#define MAXN 100001
ll read(){
ll x(0), f(1);
char ch;
while ((ch = getchar()) < 48) f = ch == '-' ? -1 : 1;
do{
x = (x << 1) + (x << 3) + (ch ^ 48);
}while ((ch = getchar()) > 47);
return x * f;
}
void uwrite(ll x){
ll tmp(x/10);
if (tmp) uwrite(tmp);
putchar(x-(tmp<<1)-(tmp<<3)^48);
}
void write(ll x){
if (x < 0){
putchar('-');
x = -x;
}
uwrite(x);
}
ll pow(int a, int b){
int res(1);
while (b--) res *= a;
return res;
}
int A, B, C;
ll k, sum;
void solve(){
A = read();
B = read();
C = read();
k = read();
for1(i, pow(10, A-1), pow(10, A)-1){
sum = min(i+pow(10, B)-1, pow(10, C)-1)-max(i+pow(10, B-1), pow(10, C-1))+1;
if (k > sum) k -= sum;
else{
write(i);
printf(" + ");
write(max(i+pow(10, B-1), pow(10, C-1))+k-1-i);
printf(" = ");
write(max(i+pow(10, B-1), pow(10, C-1))+k-1);
return;
}
}
write(-1);
}
signed main(){
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
int t(1);
t = read();
while (t--){
solve();
putchar('\n');
}
return 0;
}