Given two numbers N and K, the task is to split this number into K positive integers such that their sum is equal to N and none of these K integers is a multiple of K.
Input: N = 10, K = 3
Output: 1, 1, 8
Input: N = 18, K = 3
Output:1, 1, 16
To split N into K numbers, we need to approach the problem by the following steps:
- Check if N is divisible by K or not.
- If N is divisible by K, then N – K + 1 is not divisible by K. Hence, we can split N into N – K + 1 as one part and all the remaining K – 1 parts as 1.
- If N is not divisible by K:
- If K is 2, then it is not possible to split.
- Otherwise, split N into K-2 parts as all 1 and 2 and N – K as the remaining two parts.
Below code is the implementation of the above approach:
1, 1, 1, 2, 13
Time Complexity: O(K)
- Number of ways to split a binary number such that every part is divisible by 2
- Split the number N by maximizing the count of subparts divisible by K
- Number of ways to split N as sum of K numbers from the given range
- Split a number into 3 parts such that none of the parts is divisible by 3
- Smallest number divisible by first n numbers
- Numbers that are not divisible by any number in the range [2, 10]
- Sum of n digit numbers divisible by a given number
- Number of pairs from the first N natural numbers whose sum is divisible by K
- Count n digit numbers divisible by given number
- Smallest n digit number divisible by given three numbers
- Program to print all the numbers divisible by 3 and 5 for a given number
- Largest N digit number divisible by given three numbers
- Divide number into two parts divisible by given numbers
- Find N numbers such that a number and its reverse are divisible by sum of its digits
- Check if the number formed by the last digits of N numbers is divisible by 10 or not
- Sum of largest divisor of numbers upto N not divisible by given prime number P
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers
- Count of numbers upto M divisible by given Prime Numbers
- Split N^2 numbers into N groups of equal sum
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.