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 the minimum permutation of A greater than B
- 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 value of 1^k + 2^k + 3^k + ... + n^k
- Program to find sum of 1 + x/2! + x^2/3! +...+x^n/(n+1)!
- Program to find LCM of two numbers
- Program to find sum of series 1 + 1/2 + 1/3 + 1/4 + .. + 1/n
- Program to find GCD or HCF of two numbers
- 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)
- 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 Sum of the series 1*3 + 3*5 + ....
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.