NINJA3 - STUNNING GCD

You are given three numbers N, a, b. You can build a number X by repeating N 'a' times and the number Y by repeating N 'b' times. Now that you have the numbers X and Y, determine the GCD of the two numbers X and Y.

Input format:

The first line contains an integer T, the number of test cases.

Then for each test case, there are three integers in each line: N, a, b.

Output format:

Print the required answer for each test case in a single line.

Constraints:

1 <= T <= 100

1 <= N, a, b <= 10^18

Sample:

Input:
1
123 2 3

Output:
123

Added by:mombassa
Date:2016-02-17
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU JS-MONKEY

hide comments
2016-05-17 20:55:34
do run test cases on this to get what question is actually saying
http://www.spojtoolkit.com/test/NINJA3
Question would hav been more logical if it meant X=N*a and Y=N*b,
but here it says X=NNNNNN....a times and Y=NNNNN......b times
2016-03-08 20:35:07
N can be a larger number
2016-03-03 23:23:29 pk
Cake walk.
2016-03-03 03:44:26 Mayank Garg
Easy one .. But nyc logic :D
2016-03-02 04:10:56
comments were helpful
2016-03-01 21:32:30
A simple relation ,try few custom test case
2016-02-26 12:39:24 ATUL KUMAR SINGH
simple but after 9 wa of common mistake ac

Last edit: 2016-02-26 12:39:43
2016-02-25 20:36:41
why i am getting WA ?
test case plss..
2016-02-25 18:45:04 [Lakshman]
@dwij28 You are correct BUT do you know how much time it will take for such an massive number, this is not only the case there are many more for all n>10^9 and n <=10^18 and if a and b are (n, 2*n) .
2016-02-25 07:50:32
@[Lakshman]: Sir, I think there can be solution to the testcase you mentioned. The problem that I see in your test case is that arrays won't be sufficient to handle the answer. But the answer can be obtained without even using arrays using loops and print statement. :)
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.