Selling pills
Time limit1sMemory limit512 MB
Given N, build the fixed canonical pouch layout of (b-1) ones followed by c copies of b, where b^2 >= N and c = ceil(N/b).
- Level
Easy3 of 10
- Topics
- Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
Kanguk sells pills, and he talks his customers into a purchase every time. One thing still bothers him.
Donggyu, a regular customer, orders some number of pills every day, anywhere from to . Kanguk counted the pills out of the box one at a time, which took a while, and Donggyu lost his temper over the wait every time.
Kanguk worked out a faster way to hand the pills over. He splits the pills among several pouches and lines the pouches up in a row. When Donggyu asks for pills, Kanguk picks up one contiguous run of pouches whose pills add up to exactly .
The counter holds at most pouches in a row. Arrange the pouches so that Kanguk can serve any number from to that Donggyu calls out.
Input
The first line contains (), the largest number of pills Donggyu orders at once.
Output
Print the number of pouches () on the first line. On the second line print the number of pills in each pouch from left to right, separated by single spaces. Every pouch holds between and pills, and every number from to is the sum of some contiguous run of pouches.
Many arrangements satisfy those conditions, so the judge accepts only the arrangement built by the following rule.
- Let be the smallest positive integer with .
- Let .
- Then . Starting from the left, place pouches holding pill each, then pouches holding pills each.