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
rohit9934:
20170308 13:05:45
after a lot of struggle,Finally Green Tick 

nilabja16180:
20170301 16:48:47
python AC in one GO! 

vladimira:
20170226 18:27:32
when a = 0 just print b, cost me few wa 

scorpion_ajay:
20170216 16:48:22
care about when one of the variables is 0,,,,, costed me ample of wrong answers ;( 

rajat_singhal:
20170110 11:03:24
is A=1 and B=10^25 then b%a=b nd time limit exceed them what to do,,, 

praney_rai:
20161227 12:55:01
wow!! really a nice question.. highly recommended for beginners..


flyingduchman_:
20161120 17:19:29
CLRS textbook and Theorem 31.9 states that,


rmaurya:
20161027 19:33:04
no JAVA..:( 

sandeep_4141:
20161026 19:55:49
really take care when a==0,cost 1 WA ..but finally AC! 

sonali9696:
20160708 22:18:19
simple high school mathematics :) 
Added by:  Frank Rafael Arteaga 
Date:  20080804 
Time limit:  0.25s 
Source limit:  1000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: C99 LISP clisp LISP sbcl ERL JAVA JSRHINO NODEJS PERL PERL6 PHP PYTHON RUBY VB.NET 
Resource:  My own Resource 