#include <stdio.h>
#include <malloc.h>
#define MAX 100000
typedef struct
{
int *base;
int *top;
} stack;
void Init(stack *S)//创建栈
{
S->base = (int *)malloc(MAX * sizeof(int));
S->top = S->base;
}
void Push(stack *S, int e)//入栈
{
*(S->top++) = e;
}
void Pop(stack *S)//出栈
{
S->top--;
}
int Gettop(stack *S)//返回栈顶值
{
return *(S->top-1);
}
int Empty(stack *S)//判栈空
{
if(S->base == S->top)
return 1;
else
return 0;
}
void Transfer(stack *S,int n,int R,int flag)//进制转换
{
if(n == 0)
flag = 1;
while(n != 0)
{
Push(S,n%R);
n /= R;
}
if(flag)
printf("0");
while(!Empty(S))//输出
{
printf("%d",Gettop(S));
Pop(S);
}
}
int main()//主函数
{
int n,R,flag = 0;
stack S;
Init(&S);
scanf("%d %d",&n,&R);
Transfer(&S,n,R,flag);
return 0;
}