UVA10190




Sample Input


125 5
30 3
80 2
81 3

Sample Output


125 25 5 1
Boring!
Boring!
81 27 9 3 1


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class UVA10190 {

 public static void main(String[] args) throws NumberFormatException,
   IOException {

  int n, m;

  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

  String s = "";
  StringTokenizer stk;

  while ((s = in.readLine()) != null) {

   StringBuilder sb = new StringBuilder();

   stk = new StringTokenizer(s.trim());

   n = Integer.parseInt(stk.nextToken());
   m = Integer.parseInt(stk.nextToken());

   sb.append(n);

   int quo = n;


   boolean isBoring = m < 2 || quo < 2;

   while (!isBoring && quo > 1) {

    if (quo % m != 0)
     isBoring = true;

    quo = quo / m;

    sb.append(" " + quo);

   }

   if (isBoring) {

    System.out.println("Boring!");
   } else {

    System.out.println(sb);
   }

  }

 }

}