Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int ans[100000], h;
- void umn(int a, int base)
- {
- int c = 0, t;
- for (int i = 0; i < h || c; i++)
- {
- if (i >= h) h++;
- t = ans[i] * a + c;
- ans[i] = t % base;
- c = t / base;
- }
- }
- void pls(int a, int base)
- {
- int c = 0, t;
- if (!h) h++;
- ans[0] += a;
- for (int i = 0; i < h || c; i++)
- {
- if (i >= h) h++;
- t = ans[i] + c;
- c = t / base;
- ans[i] = t % base;
- }
- }
- int main()
- {
- int bases, basef;
- char i;
- cin >> bases >> basef >> i;
- for (;;)
- {
- pls(((i > '9') ? i - 'A' + 10 : i - '0'), basef);
- if (cin >> i) umn(bases, basef);
- else break;
- }
- for (int i = h - 1; i > -1; i--)
- cout << (char)((ans[i] > 9) ? ans[i] - 10 + 'A' : ans[i] + '0');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement