#include<bits/stdc++.h> #define int long long #define MAX(a,b,c) max(a,max(b,c)) #define MIN(a,b,c) min(a,min(b,c)) #define pb push_back #define fi first #define se second typedef long long ll; typedef long long LL; typedef unsigned long long ull; typedef unsigned long long uLL; using namespace std; const int maxn=1e6+10; map<int,char> mp; int32_t main() { mp[0]='0'; mp[1]='1'; mp[2]='2'; mp[3]='3'; mp[4]='4'; mp[5]='5'; mp[6]='6'; mp[7]='7'; mp[8]='8'; mp[9]='9'; mp[10]='A'; mp[11]='B';mp[12]='C';mp[13]='D';mp[14]='E'; mp[15]='F'; int n,m; cin>>n>>m; int num=fabs(n); int k=m; stack<char> vs; while(num) { int c=num%k; cout<<c<<endl; vs.push(mp[c]); num=num/k; } cout<<n<<"="; if(n<0) cout<<"-"; while(!vs.empty()) { cout<<vs.top(); vs.pop(); } }