Mock CCC '19 Contest 1 S4 - Pusheen Plays Neko Atsume

View as PDF

Submit solution

Points: 12
Time limit: 0.6s
Java 1.0s
Memory limit: 1G

Problem type

Pusheen is playing Neko Atsume! She has a lot of toys and has laid them out to maximize her fish income. She wants to know how efficient her layout will be though.

After doing a lot of critical thinking and real-time programming, Pusheen has boiled down the fish income in terms of a single variable - the beauty of the arrangement of toys. She thus defines f(x) to be the fish income given that her layout has beauty x. After some more computation, Pusheen has realized that for all x0, f(x)=1. Otherwise, f(x)=f(xab)+f(xcd).

Pusheen has Q layouts, layout i having beauty xi. Compute f(xi) for many values of xi.

Constraints

1xi109

2a,c109

0b,d109

1Q105

Input Specification

The first line contains five space-separated integers, a, b, c, d, and Q.

The next Q lines each contain a single positive integer, xi.

Output Specification

Output Q lines, the f(xi) values in order.

Sample Input

Copy
2 0 2 0 3
1
2
3

Sample Output

Copy
2
4
4

Comments

There are no comments at the moment.