#include #include #include #include #include #include #define SQR(x) ((x)*(x)) using namespace std; void from(int base, string str) { int N=0, Q=1; for(int i=str.size()-1; i>=0; --i) { N+=Q*(str[i]-'0'); Q*=base; } cout<0) { if (x=t) { n-=t; t*=SQR(R); L+=2; } vector bin; int x0=n,R0=abs(R); while (x0) { bin.push_back(x0%R0); x0/=R0; } bin.resize(L); // bin[L-1]=1; bin[L-1]=n/(t/(abs(R)-1))+1; for (int i=0;i=0;--i) { cout<=t) { n-=t; t*=SQR(R); L+=2; } vector bin; int x0=n,R0=abs(R); while (x0) { bin.push_back(x0%R0); x0/=R0; } bin.resize(L); // bin[L-1]=1; bin[L-1]=n/(t/(abs(R)-1))+1; for (int i=0;i=0;--i) { cout<>s, s!="end") { if(s[0]=='t') { s=s.substr(2,string::npos); int base=atoi(s.c_str()),num; cin>>num; to(base,num); } else { s=s.substr(4, string::npos); int base=atoi(s.c_str()); string t; cin>>t; from(base, t); } } }