Fight in Indiahacks

3.9

14 votes
Problem

IndiaHacks-2016 is going on and Tom and Jerry also came to participate in the contest. Tom and Jerry started fighting in the contest too, as always! As this is the INDIAHACKS Contest so this time the fight is on numbers. They ended up bringing a game to decide who is better. They have N marbles and they choose two integers M1 and M2, in each turn a player can take either M1 or M2 marbles(if available!). One who can't make any move further, loses.

Game is started with Jerry's turn always. Given N, M1 and M2, and assuming that both are playing optimally, tell us whether Jerry will win or not.

We strongly recommend you to take part in the contest with Tom and Jerry so register yourself at IndiaHacks-2016

Input:

 T, number of test cases then T lines containing three integers N, m1 and m2

Output:

 1 If Jerry wins, 0 if Tom wins.

Constraints:

0<T<100

0< m1 <= m2, N <=1000000.    Note that m1 or m2 can be greater than N.

Test files will be such that T*N < 10000000 .


Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?