A game of digits

Consider the following game: given two positive integers nn and bb, players A and B take turns to write digits in base bb (from 0 to b1b-1), starting with player A. The digits are written from left to right. For instance, if A writes a 5, B may write a 1 to form a 51, but not a 15. (And then A would write another digit, and then B, and so on.) If at any point during the game a multiple of nn (including 0) is written (in base bb), then B wins and the game finishes.

If A can indefinitely prevent B from winning, both players will eventually get bored and player A will be declared the winner. Otherwise, they will keep playing until B wins. Can you determine who will be the winner? Assume that A and B play perfectly.

Input

Input consists of several cases, each with nn and bb. Assume 1n10181 \le n \le 10^{18} and 2b10182 \le b \le 10^{18}.

Output

For every case, print the name of the winner.

Problem information

Author: Martí Oller

Generation: 2026-01-25T11:37:50.095Z

© Jutge.org, 2006–2026.
https://jutge.org