Given four integers A, B, C and D. The task is to find which is greater AB or CD.
Input: A = 2, B = 5, C = 4, D = 2
25 = 32
42 = 16
Input: A = 8, B = 29, C = 60, D = 59
Naive approach: Calculate the values of AB and CD then compare them. This approach will fail when the values are greater say 562145321457.
Efficient approach: Using log, we can write the terms as log(AB) and log(CD) which can also be written as B * log(A) and D * log(C). These values are easier to calculate and compare than the original values.
Below is the implementation of the above approach:
- Program to find whether a no is power of two
- Program to find parity
- Find minimum number to be divided to make a number a perfect square
- Find whether a given number is a power of 4 or not
- Find Union and Intersection of two unsorted arrays
- To find sum of two numbers without using any operator
- Find day of the week for a given date
- Given a number, find the next smallest palindrome
- Find the element that appears once
- Find the largest multiple of 2, 3 and 5
- Program to find amount of water in a given glass
- Find the maximum distance covered using n bikes
- Find if two rectangles overlap
- Find the smallest number whose digits multiply to a given number n
- Find next greater number with same set of digits
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.