Given three integers a, b and n, the task is to find out greater value between an and bn.
Input: a = 3, b = 4, n = 5
Output: b^n is greater than a^n
Value of an is 243 and the value of bn is 1024.
So, bn is greater than an.
Input: a = -3, b = 2, n = 4
Output: a^n is greater than b^n
Value of an is 243 and the value of bn is 16.
So, an is greater than bn.
Basic Approach: For every value of a, b and n, calculate the values of an and bn. Then compare the result obtained and display the according to output.
The problem with this approach arises when there are large values of a, b and n. For large values of a, n, calculating an can exceed the limit of integer which will cause integer overflow.
Better approach is to check the value of n.
- If n is even then calculate the absolute value of a and b.
- If n is odd then take the given value as it is.
- Now check if a is equal to b. If yes, print 0.
- If a is greater than b, print 1.
- Otherwise, print 2.
b^n is greater than a^n
- Find next greater number with same set of digits
- Find the Next perfect square greater than a given number
- Find next greater element with no consecutive 1 in it's binary representation
- Find minimum value to assign all array elements so that array product becomes greater
- Find K such that changing all elements of the Array greater than K to K will make array sum N
- Program to find sum of 1 + x/2! + x^2/3! +...+x^n/(n+1)!
- Program to find Sum of a Series a^1/1! + a^2/2! + a^3/3! + a^4/4! +…….+ a^n/n!
- Program to find last two digits of 2^n
- Program to Find the value of cos(nΘ)
- Program to find the value of sin(nΘ)
- Program to find LCM of 2 numbers without using GCD
- Program to find HCF iteratively
- Program to find the value of tan(nΘ)
- Program to find the sum of the series (1/a + 2/a^2 + 3/a^3 + ... + n/a^n)
- Program to find sum of series 1 + 1/2 + 1/3 + 1/4 + .. + 1/n
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.