2017年8月26日 星期六

UVA10190:Divide, But Not Quite Conquer!

  1. import java.util.*;  
  2. class main{  
  3. public static void main(String[] args){  
  4. Scanner sc = new Scanner(System.in);  
  5. while(sc.hasNext()){  
  6. Stack<Long> st = new Stack();  
  7. long n = sc.nextLong();  
  8. long m = sc.nextLong();  
  9. long tmp = 1;  
  10. while(m>1&&tmp<=n){  
  11. st.push(tmp);  
  12. tmp = tmp*m;  
  13. }  
  14. if(!st.empty()&&st.lastElement()==n){  
  15.    
  16. while(true){  
  17.   Long str = st.pop();  
  18.   if(str!=1)  
  19.   System.out.print(str+" ");   
  20.   else {System.out.print(str); break;}  
  21. }  
  22. System.out.println();   
  23. }else System.out.println("Boring!");  
  24. }  
  25.   
  26. }   
  27.   
  28. }  

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。