// produce binary num from pos backwards and w/o leading 1


public class HeapDecoder {
    private int position;
    private int base;
    
    public HeapDecoder(int pos, int base){
	position = pos;
	this.base = base;
    }
    
    public int getNextDigit() {
	int rem = position % base;
	position = position/base;
	return rem;
    }
    
    public boolean hasMoreDigits() {
	return (position > 1);
    }
    
    public static void main(String[] args) {
	int p = Integer.parseInt(args[0]);
	int b = Integer.parseInt(args[1]);
	HeapDecoder d = new HeapDecoder(p,b);
	String s = "Decoding " + p + "," + b + ":" ;
	while (d.hasMoreDigits()) {
	    s = s + d.getNextDigit() + " ";
	}
	System.out.println(s);
    }
}


