java參考答案
import java.util.*;//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static int caculate(long n,long m){
List<Long>list=new ArrayList<>();
if(m==0){
System.out.println("Boring!");
return 0;
}
if(m==1){
System.out.println(n+" "+"1");
return 0;
}
list.add(n);
int a=0;
while(n!=1){
if(n%m!=0){
a=1;
break;
}
else if(n%m==0){
n=n/m;
list.add(n);
}
}
if(a==1){
System.out.println("Boring!");
return 0;
}
if(a==0){
for(int i=0;i< list.size();i++){
if(i== list.size()-1){
System.out.printf("%d",list.get(i));
break;
}
System.out.printf("%d ",list.get(i));
}
}
System.out.println();
return 1;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()) {
long n = sc.nextLong();
long m = sc.nextLong();
caculate(n,m);
}
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
}
}