#include<bits/stdc++.h>
using namespace std;
#define Max 1000
typedef struct node
{
int data;
}Node;
struct Stack{
int top;
int base;
struct node *S;
};
void inStack(struct Stack &A,int num)
{
A.S[A.top++].data=num;
}
int outstack(struct Stack &A)
{
return A.S[--A.top].data;
}
void initstack(struct Stack &A)
{
A.top=A.base=0;
A.S=new Node[Max];
}
bool empty(struct Stack &A)
{
if(A.base==A.top) return true;
return false;
}
int main()
{
struct Stack A;
initstack(A);
int n;
int a,b;
cin>>a>>b;
while(a)
{
n=a%b;
a/=b;
inStack(A,n);
}
while(empty(A)==false)
cout<<outstack(A)<<" ";
}