99522024-03-21 00:21:35111Számlexikoncpp17Wrong answer 0/100170ms3992 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

auto pi = new char[10000000];
auto po = new char[10000000];
auto po0 = po;

int ru() {
	while (!isdigit(*pi)) {
		pi++;
	}
	int res = 0;
	while (isdigit(*pi)) {
		res *= 10;
		res += *pi - '0';
		pi++;
	}
	return res;
}

void wc(char c) {
	*po++ = c;
}

void wu(int i) {
	int x = 1;
	int c = 1;
	while (x <= i / 10) {
		x *= 10;
		c++;
	}
	while (c--) {
		int d = i / x;
		wc('0' + d);
		i -= d * x;
		i *= 10;
	}
}

int E(int n,int k,int j,int l,int o){
	int ans=0;
	while(true){
		while(j>0&&l>0&&k/l==n/j){
			n-=n/j*j;
			k-=k/l*l;
			l/=10;
			j/=10;
		}
		if(j==0||l>0&&k/l>n/j){
			break;
		}
		if(l==0){
			ans+=n+1;
			break;
		}
		ans+=(n/j-(k/l+1))*j;
		ans+=n%j+1;
		n=j-1;
		k-=k/l*l;
		l/=10;
		j/=10;
	}
	return ans;
}

int F(int k,int l,int o){
	int ans=0;
	while(true){
		if(l==0){
			ans+=o*10;
			break;
		}
		ans+=(10-(k/l+1))*o;
		k-=k/l*l;
		l/=10;
		o/=10;
	}
	return ans;
}

int H(int n,int k){
	if(n==0){
		return 0;
	}
	int j=1,o=1;
	while(j*10<=n){
		j*=10;
		o*=10;
		o++;
	}
	int l=1;
	while(l*10<=k){
		l*=10;
	}
	return E(n,k,j,l,o/10);
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef CB
	freopen("be2.txt","r",stdin);
//	freopen("out.txt","w",stdout);
#endif
	fread(pi,1,10000000,stdin);
	int T=ru();
	while(T--){
		int K=ru(),P=ru();
		int l=K,h=1e18;
		while(l!=h){
			int m=(l+h)/2;
			if(m-H(m,K)>=P){
				h=m;
			}
			else{
				l=m+1;
			}
		}
		wu(h-H(h,K)!=P?0:h);wc('\n');
	}
	fwrite(po0,1,po-po0,stdout);
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/100
1Wrong answer0/03ms2032 KiB
2Wrong answer0/090ms2668 KiB
3Wrong answer0/103ms2580 KiB
4Wrong answer0/103ms2784 KiB
5Wrong answer0/103ms2740 KiB
6Wrong answer0/103ms2744 KiB
7Wrong answer0/103ms3000 KiB
8Wrong answer0/104ms3212 KiB
9Wrong answer0/10170ms3752 KiB
10Wrong answer0/10100ms3992 KiB
11Wrong answer0/10101ms3976 KiB
12Wrong answer0/1037ms3976 KiB