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
- Program to find sum of 1 + x/2! + x^2/3! +...+x^n/(n+1)!
- Program to find sum of series 1 + 1/2 + 1/3 + 1/4 + .. + 1/n
- Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +.......+ n/n!
- Program to find the Depreciation of Value
- Program to find the sum of a Series (1*1) + (2*2) + (3*3) + (4*4) + (5*5) + ... + (n*n)
- Program to find the value of sin(nΘ)
- Program to find HCF iteratively
- Program to find sum of the given sequence
- Program to find Sum of the series 1*3 + 3*5 + ....
- Program to Find the value of cos(nΘ)
- Program to find the sum of the series (1/a + 2/a^2 + 3/a^3 + ... + n/a^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 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.