Sample Input 1:
27 2
Sample Output 1:
Yes
1 1 0 1 1
Sample Input 2:
121 5
Sample Output 2:
No
4 4 1
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n, b, index=1;
n = scanner.nextInt();
b = scanner.nextInt();
int[] num = new int[40];
do{
num[index++] = n%b;
n = n/b;
}while (n!=0);
boolean tag = true;
for(int i=1; i<index-i; ++i) {
if (num[i]!=num[index-i]) {
tag = false;
System.out.println("No");
break;
}
}
if (tag) {
System.out.println("Yes");
}
--index;
System.out.print(num[index]);
while(index>1) {
--index;
System.out.print(" "+num[index]);
}
}
}