Given two positive integers n and k. Find minimum positive integer x such that the (x % k) * (x / k) == n, where % is the modulus operator and / is the integer division operator.
Input : n = 4, k = 6
Explanation : (10 % 6) * (10 / 6) = (4) * (1) = 4 which is equal to n
Input : n = 5, k = 5
Output : 26
Approach: The problem has been solved using the value of K in the Set-1. In this article, we will use the factor method to solve the above problem. Given below are the steps to solve the above problem.
- Since the equation is of the form a*b = N, so a and b will be the factors of N.
- Iterate from 1 to sqrt(N) to get all the factors.
- The factors i and n/i can be either of A or B.
- If i is A and n/i is B then the number will be i*k + (n/i). We can check if this number is the one by comparing it with N, if it is then it is a number which satisfies the equation.
- If i is B and n/i is A then the number will be (n/i)*k + (i). We can check if this number is the one by comparing it with N, if it is then it is a number which satisfies the equation.
- Obtain all the numbers which satisfies the equation and print the smallest among them.
Below is the implementation of the above approach.
Time Complexity : O(sqrt(N)), where N is the given positive integer.
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.
- Divide two integers without using multiplication, division and mod operator | Set2
- Find minimum x such that (x % k) * (x / k) == n
- Find an index such that difference between product of elements before and after it is minimum
- Find a number X such that (X XOR A) is minimum and the count of set bits in X and B are equal
- Find minimum number K such that sum of array after multiplication by K exceed S
- Find the pair (a, b) with minimum LCM such that their sum is equal to N
- Minimum number of increment/decrement operations such that array contains all elements from 1 to N
- Minimum positive integer to divide a number such that the result is an odd
- Break a number such that sum of maximum divisors of all parts is minimum
- Minimum value of N such that xor from 1 to N is equal to K
- Split the number into N parts such that difference between the smallest and the largest part is minimum
- Minimum Cuts can be made in the Chessboard such that it is not divided into 2 parts
- Ways to form n/2 pairs such that difference of pairs is minimum
- Minimum operations required to modify the array such that parity of adjacent elements is different
- Minimum value to be added to X such that it is at least Y percent of N
- Minimum number of changes such that elements are first Negative and then Positive
- Minimum integer such that it leaves a remainder 1 on dividing with any element from the range [2, N]
- Minimum operations required to change the array such that |arr[i] - M| <= 1
- Minimum number of operations on a binary string such that it gives 10^A as remainder when divided by 10^B
- Remove minimum elements from the array such that 2*min becomes more than max
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.