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
ragwave: 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

aryan_r: 2016-03-08 20:35:07

N can be a larger number

pk: 2016-03-03 23:23:29

Cake walk.

Mayank Garg: 2016-03-03 03:44:26

Easy one .. But nyc logic :D

gurugs: 2016-03-02 04:10:56

comments were helpful

street_funker: 2016-03-01 21:32:30

A simple relation ,try few custom test case

ATUL KUMAR SINGH: 2016-02-26 12:39:24

simple but after 9 wa of common mistake ac

Last edit: 2016-02-26 12:39:43
ghost_wire: 2016-02-25 20:36:41

why i am getting WA ?
test case plss..

[Lakshman]: 2016-02-25 18:45:04

@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) .

dwij28: 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. :)


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