Endless Candy Party
Time limit2sMemory limit128 MB
For each s from 1 to N, find the smallest day k on which exactly s tables share the same floor(b_i/k) candies per person.
- Level
Medium7 of 10
- Topics
- Math, Hash map, Brute force
- Solved
- No attempts yet
Problem
Mirko loves parties, so he decided to throw them for his friends without end. He set up tables and put candy on every one of them: table holds candies. On the first day he invites one friend to each table, on the second day two friends to each table, on the third day three, and in general on day he invites friends to each table.
When the friends walk in, of them sit down at every table and split that table's candy equally among themselves, throwing away the candy that does not divide evenly. A person sitting at table on day therefore receives candies. After the split, a table only mingles with tables whose people received the same amount, so the tables fall into groups by the amount of candy per person.
For every from to , Mirko wants to know the earliest day on which some group holds exactly tables. Write a program that reports all answers.
Mirko refills every table to its original amount before each party starts, and everyone from one party leaves before the next one begins.
Input
The first line contains the integer , the number of tables. ()
The second line contains the integers separated by spaces, where is the number of candies on table . ()
Output
Print lines. Line contains the number of the earliest day on which a group of exactly tables mingles together, or if that day never comes.
Hint
In the first example, no two tables give the same amount per person on day 1, so every table forms a group of one and the answer for size 1 is 1. On day 2, tables 1 and 2 both give 5 candies per person and mingle, so the answer for size 2 is 2. On day 3, tables 1, 2 and 3 all give 3 candies per person. On day 6, tables 1 to 4 all give 1 candy per person. On day 12, every table gives 0 candies per person, so all five tables become one group.
In the second example, all tables hold the same amount of candy, so the amount per person is always the same. A group smaller than 3 never appears.