/************************************************
Grundlegende Algorithmen mit Java,
http://algorithmen-und-problemloesungen.de/
Copyright @2007-2008 by Doina Logofatu
************************************************/

import java.io.*;
import java.util.*;

public class P06BaseP {
    private static final String FileInputName = "baseP.in";
    private static final String FileOutputName = "baseP.out";
    
    private static void transfBase10ToP(long n, int p, PrintStream out) {
        if(n>0){
            transfBase10ToP(n/p, p, out);
            out.print(n%p) ;
        }
    }
    
    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        Scanner sc = null;
        PrintStream out= null;
        try {            
            out = new PrintStream(new File(FileOutputName));
            sc = new Scanner(new File(FileInputName ));
            while(sc.hasNextLong()) {
                long n = sc.nextLong();
                if(!sc.hasNextLong()) break;
                int p = sc.nextInt();
                out.printf("%10d in base %d = ", n, p);
                transfBase10ToP(n, p, out);
                out.println();
                //out.println("toString() " + Long.toString( n, (int)p));
                //out.println("toString() " + Long.parseLong( Long.toString( n, (int)p), (int)p ));
            }
        }
        finally {
            if (sc!=null) {
                sc.close();
            }
            if(out!=null) {
                out.close();                
            }            
        }        
    }
}
