GCD2 - GCD2


Frank explained its friend Felman the algorithm of Euclides to calculate the GCD of two numbers. Then Felman implements it algorithm

int gcd(int a, int b)
{
	if (b==0)
		return a;
	else
		return gcd(b,a%b);
}
and it proposes to Frank that makes it but with a little integer and another integer that has up to 250 digits.

Your task is to help Frank programming an efficient code for the challenge of Felman.

Input

The first line of the input file contains a number representing the number of lines to follow. Each line consists of two number A and B (0 <= A <= 40000 and A <= B < 10^250).

Output

Print for each pair (A,B) in the input one integer representing the GCD of A and B.

Example

Input:
2
2 6
10 11

Output:
2
1

Source limit is 1,000 Bytes.


hide comments
hareesh: 2016-04-29 13:26:57

Good one.... Do it in C/C++

try2catch: 2016-03-25 10:28:54

You know! I was compromising time with Java for many questions.
Now it was my turn to take some advantage, but you ruined it. (If u know wht I mean )

manas0008: 2016-01-26 05:44:10

Be careful when a==0.
Got a SIGFPE due to that.

chinmoy17_c: 2016-01-08 14:12:29

really learnt some new concepts...

xpshekhar: 2015-12-28 00:28:32

learn some new things.
nice concept.

kamran siddique: 2015-11-05 14:49:35

If python is there then y not Java .. Partiality!!!!!

darkhire21: 2015-10-22 08:27:21

python 3. 4 takes 0.02 seconds in recursive and 0.01 s in iterative..!!

Last edit: 2015-10-22 08:55:11
darkhire21: 2015-10-22 08:24:06

python should be removed from list >

alexbandeira: 2015-09-29 20:31:14

Very easy With Python! =D

coder_shishir: 2015-09-29 09:09:29

good question ...learned...!!!


Added by:Frank Rafael Arteaga
Date:2008-08-04
Time limit:1s
Source limit:1000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: C99 LISP sbcl LISP clisp ERL JAVA JS-RHINO NODEJS PERL PERL6 PHP PYTHON RUBY VB.NET
Resource:My own Resource