//using __int128 , 64bit gcc #include #include #include #include #include #include using namespace std; //resize(vector, v1,v2,...,vn); v[v1][v2]...[vn] template void resize(vector& vec, const H head){vec.resize(head);} template void resize(vector& vec, const H& head, const T ... tail){ vec.resize(head); for(auto& v: vec) resize(v, tail...); } using Int = __int128; string ltos(Int x){ string ret; if(x==0) return "0"; while(x){ ret += '0' + x%10; x /= 10; } reverse(ret.begin(), ret.end()); return ret; } Int cnt_kadomatsu_digit(string s){ //dp[ x[i-2] ][ x[i-1] ][ is_small ] vector>> dp; resize(dp, 11,11, 2); dp[10][10][0] = 1; for(int i=0; i>> dp_; resize(dp_, 11,11, 2); int k = s[i] - '0'; for(int a=0; a<=10; a++) for(int b=0; b<=10; b++) for(int s=0; s< 2 ; s++){ if(!dp[a][b][s]) continue; for(int c=0; c<10; c++){ if(s==0 && c>k) continue; int next_s = s || cc && a!=c) || (a>b && b> input; Int n = 0; for(Int i=input.size()-1, k=1; i>=0; i--, k*=10){ n += (input[i]-'0') * k; } n += cnt_kadomatsu_digit(ltos(99)); Int lb = 1; Int ub = (Int(1))<<120;//Int(1LL<<58)*Int(1LL<<58); while(ub-lb>1){ Int mid = (lb+ub)/2; bool ok = cnt_kadomatsu_digit(ltos(mid)) >= n; (ok? ub : lb) = mid; } cout << ltos(ub) << endl; return 0; } #include int main(){ //auto s = clock(); int t; cin >> t; while(t--){ main_(); } //cerr << clock()-s << endl; return 0; }