Another Contest 8 Problem 3 - Replay Double Ignition

View as PDF

Submit solution


Points: 10
Time limit: 0.25s
Memory limit: 1G

Problem type

Brandon likes Fibonacci numbers. For the purposes of this problem, the Fibonacci sequence is defined as the sequence of integers f, where f1=f2=1, and fi=fi1+fi2 for i3.

One day, Brandon writes down the sequence f starting with f1, except that because he does not have good arbitrary-precision arithmetics available to him, he ends up writing down the values of fi modulo M. He wants to know the Nth digit he writes down for several different values of N.

Constraints

2M104

1Ni1018

1Q106

Input Specification

The first line contains two positive integers, M and Q.

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

Output Specification

Output Q lines. On the ith line, output the Nith digit that Brandon wrote down.

Sample Input 1

Copy
10 11
1
2
3
4
5
6
7
8
9
10
11

Sample Output 1

Copy
1
1
2
3
5
8
3
1
4
5
9

Sample Input 2

Copy
100 11
1
2
3
4
5
6
7
8
9
10
11

Sample Output 2

Copy
1
1
2
3
5
8
1
3
2
1
3

Comments

There are no comments at the moment.