Given two numbers ‘a’ and ‘b’ such that (0 <= a <= 10^12 and b <= b < 10^250). Find the GCD of two given numbers.
Input: a = 978 b = 89798763754892653453379597352537489494736 Output: 6 Input: a = 1221 b = 1234567891011121314151617181920212223242526272829 Output: 3
Solution : In the given problem, we can see that first number ‘a’ can be handled by long long int data type but second number ‘b’ can not be handled by any int data type. Here we read second number as a string and we will try to make it less than and equal to ‘a’ by taking it’s modulo with ‘a’.
Below is implementation of the above idea.
This article is contributed by Shashank Mishra (Gullu).This article is reviewed by team GeeksforGeeks . Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Sum of two large numbers
- LCM of two large numbers
- Remainder with 7 for large numbers
- Difference of two large numbers
- Divisible by 37 for large numbers
- Sort an array of large numbers
- Find Last Digit of a^b for Large Numbers
- Sum of first N natural numbers when N is extremely large
- Large Fibonacci Numbers in Java
- Sum of all natural numbers from L to R ( for large values of L and R )
- Multiply Large Numbers represented as Strings
- Writing power function for large numbers
- Multiply Large Numbers using Grid Method
- Last digit of Product of two Large or Small numbers (a * b)
- Modulo power for large numbers represented as strings