#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; vector< pair > U(40); vector< pair > D(40); int sign(LL a) { if( a < 0) return -1; if( a > 0 ) return 1; return 0; } LL abs(LL a) { if( a < 0) return -a; return a; } long long pot[12][20]; int main() { for(int e=0;e<=10;e++) pot[e][0]=1; for(int e=0;e<=10;e++) for(int p=1;p<20;p++) pot[e][p]=pot[e][p-1]*e; string S; while(1) { getline(cin, S); if(S == "end") break; if(S[0] == 'f') { S = S.substr(4); istringstream is(S); LL sys,num; is >> sys >> num; LL wyn = 0; wyn+= num%10; num/=10; LL mn = sys; while(num) { wyn+=(num%10) * mn; mn*=sys; num/=10; } cout << wyn << endl; } if(S[0] == 't') { S = S.substr(2); istringstream is(S); LL sys,num; is >> num >> sys; num=-num; int wart; int odp[20]; for(int u=0;u<20;u++) odp[u]=0; D.clear(); U.clear(); D.push_back(pair (0,1)); U.push_back(pair (0,num)); int pod=1,pocz,kon; int offset=0; int licznik=20; while(--licznik){ for(int u=1;u (pocz,kon)); //cout<<"Prze "<< pocz <<" "< (pocz,kon)); //cout<<"Prez "<< pocz <<" "< (pocz,kon)); pocz=kon; if (u+1 (pocz,kon)); } offset+=(num-1)*pod; pod=pod*num*num; } //cout<<"Czyt "<< sys <<"\n"; // cout<<"Czyt "<< num <<"\n"; if (sys==0) printf("0\n"); else{ int kolej=0; while(sys!=0){ kolej++; // cout<<"Czyt "<< sys <<"\n"; //cout<<"Czyt "<< kolej <<"\n"; //int g; //scanf("%d",&g); int parz; if (sys>0){ for(int t=0;D.size();t++){ if ( D[t].first >= sys && sys <= D[t].second ) {parz=t%2; //cout<<"Prz "<< D[t].first <<" "<wart) {v=v-1;break;} } for(int vv=1;vv= sys && sys <= U[t].second ) {//cout<<"Prz- "<< U[t].first <<" "<wart) {v=v-1;break;} } for(int vv=1;vv=0;u--) if (odp[u]!=0) {numer=u;break;} for(int u=numer;u>=0;u--) printf("%d",odp[u]); printf("\n"); //for(int u=0;u<20;u++) cout< T(40,0); if( 0 <= num < sys) { cout << num << endl; continue; } int i = 0; */ /* for(int i = 2;i<40;i+=2) { mn*sys*sys; TD[i].first = mn; TD[i].second = mn*(sys-1) + TD[i-2].second; } */ /* mn = sys; for(int i = 1;i<40;i+=2) { TU[i].first = mn; mn*sys*sys; TU[i].second = mn*(sys-1) + TD[i-2].second; } for(int i = 25;i>= 0;i++) { if(sign(num) == 0) cout << "0"; if( sign(num) == 1) { } else { } }*/ // cout << wyn << endl; } } return 0; }