Submit | All submissions | Best solutions | Back to list |
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.
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 |
hide comments
|
|||||||||||||
2012-12-01 21:14:01 Paul Draper
Why no Java? |
|||||||||||||
2012-10-01 19:26:45 Mathan Kumar
What is the o/p for 0 and 0?? |
|||||||||||||
2012-08-20 15:16:03 StupidGuy
Why no Python 2.7? |
|||||||||||||
2012-05-23 13:38:32 napster
nice one!!! |
|||||||||||||
2012-03-23 07:15:50 bond 007
runtime error (NZEC) can anyone explain me about this error? |
|||||||||||||
2011-06-12 10:47:21 oldmonk
give me some test case it 's giving WA |
|||||||||||||
2011-05-03 14:11:51 Piotr KÄ…kol
Also don't understand why such strange language restriction. But looking on the author's status it seems that he won't visit this page soon... :-/ |
|||||||||||||
2011-01-04 13:22:52 :D
Floating point error, most often division by 0. You should read the tutorial. |
|||||||||||||
2011-01-04 11:05:13 Fernandes Sinaga
what mean of RE SIGFPE?? |
|||||||||||||
2010-12-19 13:18:45 yyf
if a=0 then just print b |