Given two integers N and D, Find a set of N integers such that difference between their product and sum is equal to D.
Input : N = 2, D = 1 Output : 2 3 Explanation: product = 2*3 = 6, Sum = 2 + 3 = 5. Hence, 6 - 5 = 1(D). Input : N = 3, D = 5. Output : 1 2 8 Explanation : Product = 1*2*8 = 16 Sum = 1+2+8 = 11. Hence, 16-11 = 5(D).
A tricky solution is to keep the difference D to choose N numbers as N-2 ‘1’s, one ‘2’ and one remaining number as ‘N+D’.
Sum = (N-2)*(1) + 2 + (N+D) = 2*N + D.
Product = 1*2*(N+D) = 2*N+2*D
Difference = (2*N+2*D) – (2*N+D) = D.
1 2 8
- Find distinct integers for a triplet with given product
- Find a pair with maximum product in array of Integers
- Find an index such that difference between product of elements before and after it is minimum
- Maximum GCD of N integers with given product
- Check whether product of integers from a to b is positive , negative or zero
- Counting numbers whose difference from reverse is a product of k
- Absolute difference between sum and product of roots of a quartic equation
- Find two integers A and B such that A ^ N = A + N and B ^ N = B + N
- Find the prime P using given four integers
- Find the number of integers from 1 to n which contains digits 0's and 1's only
- Find three integers less than or equal to N such that their LCM is maximum
- Find the first N integers such that the sum of their digits is equal to 10
- Find all the possible remainders when N is divided by all positive integers from 1 to N+1
- Find n positive integers that satisfy the given equations
- Find the integers that doesnot ends with T1 or T2 when squared and added X
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.
Improved By : jit_t