Vouchers
Time limit3sMemory limit128 MB
Each day k removes the a_k smallest remaining package sizes divisible by a_k; report which customers buy packages that hold vouchers.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Simulation, Implementation
- Solved
- No attempts yet
Problem
A candy shop sells caramel candies. For every positive integer there is exactly one package that contains exactly candies, so the packages have sizes , one package of each size, and no new deliveries will arrive.
To reward customers, the owner has hidden vouchers, each good for a year's supply of chocolate. Each voucher is placed in a different package (at most one voucher per package); the -th voucher sits in the package of size .
The town's carnival lasts days. On day a party with guests is held. On the morning of day , each of those guests buys the smallest package still on sale whose candy count is divisible by , so that it can be split evenly among the guests. Because there are guests, day removes the smallest still-available packages whose size is a multiple of , in increasing order of size.
Customers are numbered across the whole carnival in the order they buy: all of an earlier day's buyers come before a later day's, and within one day the buyer of a smaller package gets the smaller number.
For example, with , , , on day 1 the packages of candies are sold, and on day 2 the packages of and candies are sold.
Determine which customers end up buying a package that holds a voucher.
Input
The first line contains an integer (), the number of vouchers.
Each of the next lines contains an integer (), the size (number of candies) of the package holding the -th voucher. The values are given in strictly increasing order.
The next line contains an integer (), the number of carnival days.
Each of the next lines contains an integer (), the number of guests at the party on day .
Output
Print an integer on the first line: the number of vouchers that are sold.
On the next lines print, in increasing order, the numbers of the customers who bought a package containing a voucher. If , print only the first line.