Given an integer N, the task is to find two numbers a and b such that a / b = N and a – b = N. Print “No” if no such numbers are possible.
Input: N = 6
a = 7.2
b = 1.2
For the given two numbers a and b, a/b = 6 = N and a-b = 6 = N
Input: N = 1
There are no values of a and b that satisfy the condition.
Approach: To solve the problem observe the equations derived below:
On solving above equations simultaneously, we get:
Since the denominator is N – 1, so the answer will not be possible when N = 1. For all other cases, the answer is possible. Hence find the values of a and b respectively.
Below is the implementation of the above approach:
a = 7.2 b = 1.2
Time Complexity: O(1)
Auxiliary Space: O(1)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Maximum value of division of two numbers in an Array
- Number of digits before the decimal point in the division of two numbers
- Find two Composite Numbers such that there difference is N
- Find two numbers with the given LCM and minimum possible difference
- Find the number after successive division
- Program to find the percentage of difference between two numbers
- Find two numbers such that difference of their squares equal to N
- Find two numbers whose difference of fourth power is equal to N
- Program to find the maximum difference between the index of any two different numbers
- Find two numbers made up of a given digit such that their difference is divisible by N
- Find the minimum difference between Shifted tables of two numbers
- Find Quotient and Remainder of two integer without using division operators
- Long Division Method to find Square root with Examples
- Absolute difference between the Product of Non-Prime numbers and Prime numbers of an Array
- Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array
- Difference of two large numbers
- Numbers having difference with digit sum more than s
- Modular Division
- DFA based division
- Division without using '/' operator
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.