Given a big positive number N. The task is divide N into two number ‘A’ and ‘B’ such that difference between them is K (1 <= K <= 10100) i.e A – B = K.
Input : N = 10, K = 2 Output : A = 6 B = 4 Input : N = 20, K = 4 Output : A = 12 B = 8
Let the two required number be ‘A’ and ‘B’. So, we know sum of ‘A’ and ‘B’ will end upto N.
So, one equation became,
A + B = N
And also, we want the difference between ‘A’ and ‘B’ equals to ‘K’.
So, another equation becomes,
A – B = K
On adding both the equation, we get
2*A = N + K
So, A = (N + K)/2
Then we can find B by, B = (N – A)
Now, to handle the Big Integer, we have store Integers in character array and define a function to perform the operation on them.
Below is C implementation of this approach:
- Divide a number into two parts
- Divide number into two parts divisible by given numbers
- Divide a number into two parts such that sum of digits is maximum
- Count number of ways to divide a number in 4 parts
- Find the number of ways to divide number into four parts such that a = c and b = d
- Divide an isosceles triangle in two parts with ratio of areas as n:m
- Minimum cuts required to divide the Circle into equal parts
- Split a number into 3 parts such that none of the parts is divisible by 3
- Break the number into three parts
- Partition a number into two divisble parts
- Possible cuts of a number such that maximum parts are divisible by 3
- Sum of all second largest divisors after splitting a number into one or more parts
- Break a number such that sum of maximum divisors of all parts is minimum
- Find count of digits in a number that divide the number
- Split the number into N parts such that difference between the smallest and the largest part is minimum
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.