HG - HUGE GCD
RK has received a homework assignment to compute the greatest common divisor of the two positive integers A and B. Since the numbers are quite large, the professor provided him with N smaller integers whose product is A, and M integers with product B.
RK would like to verify his result, so he has asked you to write a program to solve his problem. If the result is more than 9 digits long, output only the last 9 digits.
The first line of input contains the positive integer N (1<= N<= 1000).
The second line of input contains N space-separated positive integers less than 10^9, whose product is the number A.
The third line of input contains the positive integer M (1 <=M <= 1000).
The fourth line of input contains M space-separated positive integers less than 10^9, whose product is the number B.
The first and only line of output must contain the greatest common divisor of numbers A and B. If the result is more than 9 digits long, output only the last (least significant) 9 digits.
2 3 5
358572 83391967 82
50229961 1091444 8863
First sample description: The greatest common divisor of numbers A = 30 and B = 20 equals 10.
In c++ ,use your logic with long int and you should use printf ,scanf instead of cin,cout >>:)
Guys, I'm stuck . Getting WA :(
BigInteger makes it so easy! Don't forget to observe the output condition!!
INTEGER in JAVA !!!
Stupid question, since the '0's are to be printed unnecessarily. The answer MODULO 10^9+7 is a much better and convenient alternative. So many changes had to be done to my code for such a trivial demand.
I am getting NZEC error, could you please help me with this. http://ideone.com/cD9irG
getting wrong answer -_- -_- using biginteger too nd still :/ someone hint or help plz
AC in one attempt :D :D
Done in python......Best python solution..... :)Last edit: 2015-05-26 11:06:54
Will O(m*n) be sufficient or do I need more efficient code?