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-09-04 11:50:08 jarvis
Dear zero :/ costed 1 SIGSEV and two WA Finally AC :) |
|||||||||||||
2015-08-24 03:41:57 Shivam Singh
its all about getting the first B%A... |
|||||||||||||
2015-08-21 16:53:52 alok singh
sahi hai :) |
|||||||||||||
2015-08-18 03:02:31 sarvagya
do it in C,C++ if you want to learn else move to another problem . :P |
|||||||||||||
2015-08-06 18:33:40 Anurag Sharma
python should also remove.... |
|||||||||||||
2015-08-06 18:30:51 Anurag Sharma
why there is not java included.... it sucks :< |
|||||||||||||
2015-08-06 18:30:50 Anurag Sharma
why there is not java included.... it sucks :< |
|||||||||||||
2015-08-01 21:13:48
https://souvikpal.wordpress.com/2013/02/09/gcd-of-a-very-large-number/ read this it really helped me a lot :D ac in 1st go learnt a new thing :p |
|||||||||||||
2015-07-26 15:42:16 :?ToRpiDo
my...Half Century :-) done in 4 languages :-) Last edit: 2015-07-26 15:43:03 |
|||||||||||||
2015-06-04 16:42:11 Rishabh Joshi
Copy paste in python gets AC. It would be better if you only allowed languages that don't have BIGINT built in. |