Candy's Candy
Time limit1sMemory limit128 MB
Count the ways to split F flavors' counts into equal-size packs, some single-flavor and at least one containing all flavors, with each flavor having a flavored pack.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Implementation, Combinatorics
- Solved
- No attempts yet
Problem
Candy has candy in different flavors, and she wants to make several packs to sell them. Each pack is one of two kinds:
- flavored pack: contains candy of a single flavor;
- variety pack: contains candy of every flavor.
Candy calls a packing nice if it satisfies all of the following conditions:
- Every piece of candy is placed in exactly one pack.
- Every pack, of either kind, contains at least pieces of candy.
- Every pack, of either kind, contains the same number of pieces of candy.
- Within each variety pack, the number of pieces of each flavor is the same.
- There is at least one variety pack.
- For every flavor, there is at least one flavored pack of that flavor.
Candy wonders how many different nice packings she can make. Two nice packings are considered different if they differ in the number of flavored packs, in the number of variety packs, or in the number of pieces of candy per pack.
Input
The input consists of several test cases. Each test case is given on two lines. The first line contains an integer (), the number of flavors. The second line contains integers (), the number of pieces of candy of each flavor.
The last test case is followed by a line containing a single .
Output
For each test case, output on its own line the number of different nice packings that can be made according to the rules above.