Given two integer X and Y, the task is compare XY and YX for large values of X and Y.
Input: X = 2, Y = 3
Output: 2^3 < 3^2
23 < 32
Input: X = 4, Y = 5
Output: 4^5 > 5^4
Naive approach: A basic approach is to find the values XY and YX and compare them which can overflow as the values of X and Y can be large
Better approach: Taking log of both the equations, log(XY) = Y * log(X) and log(YX) = X * log(Y). Now, these values can be compared easily without overflows.
Below is the implementation of the above approach:
4^5 > 5^4
- Sum of all natural numbers from L to R ( for large values of L and R )
- Multiply large integers under large modulo
- Find (a^b)%m where 'b' is very large
- LCM of two large numbers
- Find (a^b)%m where 'a' is very large
- Sum of two large numbers
- GCD of two numbers when one of them can be very large
- Divisible by 37 for large numbers
- Divisibility by 12 for a large number
- Knapsack with large Weights
- Recursive sum of digit in n^x, where n and x are very large
- Find N % 4 (Remainder with 4) for a large value of N
- Remainder with 7 for large numbers
- Factorial of a large number
- Difference of two large numbers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.