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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Print all K digit repeating numbers in a very large number
- Find (a^b)%m where 'a' is very large
- Recursive sum of digit in n^x, where n and x are very large
- Check whether a very large number of the given form is a multiple of 3.
- Find (a^b)%m where 'b' is very large
- Series summation if T(n) is given and n is very large
- Comparing X^Y and Y^X for very large values of X and Y
- Number of factors of very large number N modulo M where M is any prime number
- How to store a very large number of more than 100 digits in C++
- Maximise the sum of two Numbers using at most one swap between them
- Multiply large integers under large modulo
- Find two numbers with sum N such that neither of them contains digit K
- Count of arrays in which all adjacent elements are such that one of them divide the another
- Minimum number of integers required such that each Segment contains at least one of them
- Check if a large number can be divided into two or more segments of equal sum
- Pair of integers having least GCD among all given pairs having GCD exceeding K
- Sum of two large numbers
- Difference of two large numbers
- LCM of two large numbers
- Last digit of Product of two Large or Small numbers (a * b)