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
|
|||||||||||||
2015-05-20 14:37:33 Tejas Meshram
got to know about boost :) (y) |
|||||||||||||
2015-02-14 17:23:05 Rahul Jain
never thought that my century would end up with solving such a silly problem :( |
|||||||||||||
2015-02-09 13:15:57 Madhav
good question..learnt something new!! |
|||||||||||||
2015-01-07 08:46:05 Aayush
Just copy-pasted gcd() in python. AC :/ |
|||||||||||||
2015-01-05 08:57:15 Abhinandan Agarwal
guys, add the 0 xepction |
|||||||||||||
2014-12-13 13:10:55 Jackson
got WA since forgot to add new line in "0" exception... Easy One... |
|||||||||||||
2014-12-02 11:16:19 reddappa
getting WA pls chk id = 13031100 |
|||||||||||||
2014-11-10 15:32:05 pankaj
after 2 WA got AC |
|||||||||||||
2014-10-23 11:04:11 premsai
keep getting WA, checked all test cases, id=12699717 Last edit: 2014-10-23 11:05:06 |
|||||||||||||
2014-10-21 12:02:58 Vamsi Krishna Avula
@atheistaltini pypy and pyth 3.4 are available only in cube cluster. |