andy6804tw
7/15/2016 - 11:15 AM

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1131 困難度 ★ 這題要注意的地方有很多 1.溢位的問題所以要使用long 2.第二

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1131 困難度 ★ 這題要注意的地方有很多 1.溢位的問題所以要使用long 2.第二個數字b >= 2 當輸入0或1時答案是Boring! 第一個數字要大於第二個a >= b 輸入 2 2=>2 1 2 0=>Boring! 2 1=>Boring! 3.每筆測資的最後一個數字輸出後面無空白

import java.util.*;
 
public class Main {
 
 public static void main(String[] args) {
  Scanner scn = new Scanner(System.in);
  while (scn.hasNext()) {
   long a = scn.nextInt(), b = scn.nextInt(), tot = 1;
   while (tot < a && b >= 2)
    tot *= b;
   if (tot == a && b >= 2 && a >= b) {
    for (long i = a; i >= 1; i /= b) {
     System.out.print(i);
     if (i != 1)
      System.out.print(" ");
    }
    System.out.println();
   } else
    System.out.println("Boring!");
  }
 }
 /* 
    題目:Q10190: Divide, But Not Quite Conquer!
    作者:1010
    時間:西元 2016 年 7 月 */
 
}