NINJA3 - STUNNING GCD

no tags 

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

hide comments
[Lakshman]: 2016-02-23 08:36:42

I have doubt what will be the output if input is 123 1000000000 1000000000000000000?

EDIT:: Every solution will fail if you consider the above input.

Last edit: 2016-02-23 09:39:10
farhan764: 2016-02-23 07:45:13

N 'a' times mean concatenates N 'a' times

Shivam Garg: 2016-02-22 21:34:18

does repeating N 'a' times mean X=N*a , or concatenating N 'a' times?

Ankit: 2016-02-21 09:25:38

the answers need to be in the single line, or on separate lines ? Little confusing.

Last edit: 2016-02-21 09:25:47
farhan764: 2016-02-21 08:30:08

@dungeon_master:=> would u plz provide output of these test cases

Siddharth Singh: 2016-02-21 07:12:09

Easy , AC in 1 Go
@azam
Try these test cases
12 4 6
7 3 5
177 3 9
these 3 are enough to decipher to logic for this problem
@farhan764, if i type the output u will instantly get the logic
if u really want to solve this problem
create a gcd function , giv it the inputs i have specific making X and Y.
u'll get the logic . all the best
@ankit
the output has to be on a new line for every test case just like for any other problem on SPOJ

Last edit: 2016-02-21 11:24:57
azam_9: 2016-02-20 16:01:34

dont knw y i m getting WA..plz give some tricky test cases.


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