Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <algorithm>
- #include <vector>
- #include <stack>
- #include <queue>
- #include <string>
- #include <math.h>
- using namespace std;
- void main()
- {
- int k,l,m;
- cin >> k >> l >> m;
- if (k>l || m<0 || k<=1 || l<=1)
- {
- cout << "WTF?";
- return;
- }
- queue<int> q;
- if (m==0) q.push(0);
- while(m!=0)
- {
- q.push(m%l);
- m/=l;
- }
- int n=0;
- int b=1;
- while(q.empty()==false)
- {
- int d=q.front();
- if (d>=k)
- {
- cout << "WTF?";
- return;
- }
- n+=b*d;
- b*=k;
- q.pop();
- }
- cout << n;
- }
Add Comment
Please, Sign In to add comment