Cheerio Contest 2 P3 - Digits

View as PDF

Submit solution

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Farmer Bob has two numbers A and B, which can be represented as a string of X 9s and a string of Y 9s respectively. He wants to find out the product of A and B (which he will call P). Bob soon realizes that P will be extremely big, so he will ask Q questions about P instead. For the ith question, he wants to know the value of the qith digit in P when counting from the left. Can you write a program to help him?

Constraints

For all subtasks:

  • 1Q5×105
  • qi will not exceed the number of digits in P.
  • 1X,Y1018
Points Awarded Additional Constraints
2 points 1X,Y9
6 points X=1 and 1Y1018
7 points No further constraints

Input Specification

The first line contains three integers X, Y and Q.

The next Q lines contain an integer qi.

Output Specification

Output Q lines, with the ith line containing the answer to the ith question.

Sample Input

Copy
3 4 2
1
5

Sample Output

Copy
9
0

Explanation for Sample

Since A=999 and B=9999, P=999×9999=9989001.


Comments

There are no comments at the moment.