76 {
77 int m, n;
78 string x;
79 cin >> m >> n >> x;
80 if(x == "0") {
81 cout << "0";
82 return 0;
83 }
84 vector<unsigned short> input = vector<unsigned short>();
85 vector<unsigned short> ans = vector<unsigned short>();
86 queue<unsigned short> quotient = queue<unsigned short>();
87 for(auto i = x.begin(); i != x.end(); i++) {
88 if(isdigit(*i)) {
89 input.push_back(*i - '0');
90 } else if(isupper(*i)) {
91 input.push_back(*i - 'A' + 10);
92 }
93 }
94 do {
95 unsigned int current = 0;
96 quotient = queue<unsigned short>();
97 for(auto i = input.begin(); i != input.end(); i++) {
98 current *= m;
99 current += *i;
100 quotient.push(current / n);
101 current %= n;
102 }
103 while(!quotient.empty() && quotient.front() == 0) {
104 quotient.pop();
105 }
106 ans.push_back(current);
107 input = vector<unsigned short>(quotient.size());
108 for(unsigned int i = 0; i < input.size(); i++) {
109 input[i] = quotient.front();
110 quotient.pop();
111 }
112 } while(!input.empty());
113 for(
auto i =
ans.rbegin(); i !=
ans.rend(); i++) {
114 if(*i < 10) {
115 cout << *i;
116 } else {
117 cout << (char) (*i - 10 + 'a');
118 }
119 }
120 return 0;
121 }
vector< vector< int > > ans