$25
CMPUT 275 - Tangible Computing
Morning Problem: Cake Cutting
Description
Bob is very particular, he only likes when his cake is cut into a power of n slices. In fact,
he despises any such cake that is not to his liking so much so that he throws it out. The
problem is, Bob has trouble with math and he throws out perfect cakes all the time... how
wasteful!
Bob would like someone to write a program that tells him whether or not a cake of m
slices is cut into a power of n so he can stop needlessly throwing out his favourite treat.
Your goal is to write this program for Bob, given a cake cut into m slices you must determine whether or not there are a power of n slices of cake.
Input
The first and only line of input contains two space-separated integers, n (1 ≤ n ≤ 500), the
base Bob likes, and m (1 ≤ m ≤ 1, 000, 000), the amount of slices of cake.
Output
You are to output one line containing either “GOOD” if there are a power of n slices of cake,
or “BAD” if there are not.
Sample Input 1
2 4
Sample Output 1
GOOD
Explanation:
There are 4 slices of cake which is 22
, so Bob will not throw out this cake.
Sample Input 2
5 3
Sample Output 2
BAD
Explanation:
There are only 3 slices of cake, which is in between 50 and 51
, so this is a bad cake.