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.
- Find two numbers with sum and product both same as N
- Number of digits before the decimal point in the division of two numbers
- Maximum value of division of two numbers in an Array
- Find Quotient and Remainder of two integer without using division operators
- Maximum length of subarray consisting of same type of element on both halves of sub-array
- Find all numbers up to N which are both Pentagonal and Hexagonal
- Multiply two integers without using multiplication, division and bitwise operators, and no loops
- Divide two integers without using multiplication, division and mod operator | Set2
- Loss when two items are sold at same price and same percentage profit/loss
- Numbers in range [L, R] such that the count of their divisors is both even and prime
- Count numbers upto N which are both perfect square and perfect cube
- Choose points from two ranges such that no point lies in both the ranges
- Partition an array of non-negative integers into two subsets such that average of both the subsets is equal
- Divide array in two Subsets such that sum of square of sum of both subsets is maximum
- Check whether two strings can be made equal by reversing substring of equal length from both strings
- Find ΔX which is added to numerator and denominator both of fraction (a/b) to convert it to another fraction (c/d)
- Find the number after successive division
- Long Division Method to find Square root with Examples
- Write you own Power without using multiplication(*) and division(/) operators
- Minimum steps to convert X to Y by repeated division and multiplication
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.