close

--------
package uva10190;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author awesq
 */
public class UVa10190 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            while (sc.hasNextInt()) {
                boolean flag = true;
                double a = sc.nextDouble();
                final double b = sc.nextDouble();
                ArrayList al = new ArrayList();

                if (b == 1 || a == 1 || a < b) {
                    System.out.println("Boring!");
                    continue;
                }

                al.add(a);
                while (a != 1) {
                    double quotient = a / b;
                    if (quotient != Math.floor(quotient)) {
                        flag = false;
                        break;
                    }
                    a /= b;
                    al.add(a);
                }
                if (!flag) {
                    System.out.println("Boring!");
                    continue;
                } else {
                    System.out.print("" + ((Double) al.get(0)).intValue());
                    for (int i = 1; i < al.size(); i++) {
                            int res = ((Double) al.get(i)).intValue();
                            System.out.print(" " + res);
                    }
                    System.out.println("");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
 

arrow
arrow
    全站熱搜

    awesq123 發表在 痞客邦 留言(0) 人氣()