CF-[CF1836C] k-th equality 题解
C:k-th equality
C - k-th equality
基本思路:
假设式子是
由
时间复杂度:
为什么可以这样的复杂度,
Each input file has at most
5 test cases which do not satisfyA, B, C \leq 3 .最多有
5 个测试用例不满足A, B, C \leq 3 。
代码实现:
核心代码:
int qmi(LL a, int k){
int res = 1;
for(; k; k >>= 1, a = a * a) if(k & 1) res = res * a;
return res;
}
void ans(int a, int b){
prf("%d + %d = %d\n", a, b, a + b);
}
int main(){
int T; rd(T);
while(T--){
LL a, b, c, k; rd(a, b, c, k);
bool f = true;
int l = qmi(10, a - 1), r = qmi(10, a) - 1;
rep(i, l, r){
int L = max(qmi(10, b - 1), qmi(10, c - 1) - i);
int R = min(qmi(10, b) - 1, qmi(10, c) - 1 - i);
if(L > R) continue;
int temp = R - L + 1;
if(k <= temp){
ans(i, L + k - 1);
f = false;
break;
}
k -= temp;
}
if(f) puts("-1");
}
return 0;
}
完整代码