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
- Divisible by 37 for large numbers
- Difference of two large numbers
- Sort an array of large numbers
- Find Last Digit of a^b for Large Numbers
- Large Fibonacci Numbers in Java
- Sum of first N natural numbers when N is extremely large
- Writing power function for large numbers
- Last digit of Product of two Large or Small numbers (a * b)
- Multiply Large Numbers represented as Strings
- Modulo power for large numbers represented as strings
- Multiply large integers under large modulo
- Find (a^b)%m where 'b' is very large