![]() |
VOOZH | about |
Given n, print the maximum number of composite numbers that sum up to n. First few composite numbers are 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, ………
Examples:
Input: 90
Output: 22
Explanation: If we add 21 4's, then we
get 84 and then add 6 to it, we get 90.
Input: 10
Output: 2
Explanation: 4 + 6 = 10
Below are some important observations.
So the main observation is to make n such that is composes of maximum no of 4’s and the remaining can be made up by 6 and 9. We won’t need composite numbers more than that, as the composite numbers above 9 can be made up of 4, 6, and 9 if it is possible to make them up with composite numbers.
Below is the implementation of the above approach
Output:
22
34
Time complexity: O(1)
Auxiliary Space: O(1)