Mojo, Jojo and Game
Practice
3 (7 votes)
Algorithms
Approved
Easy Medium
Dynamic programming
Problem
44% Success 2631 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

After solving some programming problems, Mojo and Jojo want to take some time off and play some game. They ask Rhezo what to play. Rhezo tells them about a game with the following rules:

There are N stacks of coins, each containing X coins. Both players take turns, with Mojo moving first. The only allowed moves are the following:

  1. Remove any stack of coin.

  2. Remove any 2 stacks.

  3. Remove \(X/2\) coins from each stack if X is even, or remove \((X+1)/2\) coins from each pile, if X is odd.

The game finishes when there are no more coins left in any stack. The last person to make the move wins. Both, Mojo and Jojo play optimally and want to win. Can you tell who will win this game?

Input:

First line of the input contains an integer T, denoting the number of test cases you have to handle.
Each test case consists of two integers, N and X, separated by a single space.

Output:

For each test case, if Mojo wins, print "Mojo", else print "Jojo" (quotes only for clarity).

Constraints:

  • \(1 \le T \le 10^3\)
  • \(1 \le N \le 10^3\)
  • \(1 \le X \le 10^9\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
18 votes
Tags:
Dynamic Programminggcddp on digitsdigit dpGreatest common divisormediumAlgorithmsEasy-MediumDigit DParithemtic operationsGreatest common divisorDynamic programming
Points:30
3 votes
Tags:
Dynamic ProgrammingAlgorithmsEasy-MediumDynamic programming
Points:30
9 votes
Tags:
AlgorithmsEasy-MediumdpDynamic ProgrammingDynamic programming