#P17065. [ICPC 2017 Shenyang R] BBP Formula

[ICPC 2017 Shenyang R] BBP Formula

Problem Description

In 1995, Simon Plouffe discovered a special summation style for some constants. Two years later, together with the paper of Bailey and Borwein published, this summation style was named as the Bailey-Borwein-Plouffe formula. Meanwhile, a sensational formula appeared. That is

$$\pi = \sum_{k=0}^{\infty} \frac{1}{16^k} \left( \frac{4}{8k+1} - \frac{2}{8k+4} - \frac{1}{8k+5} - \frac{1}{8k+6} \right)$$

For centuries it had been assumed that there was no way to compute the nn-th digit of π\pi without calculating all of the preceding n1n - 1 digits, but the discovery of this formula laid out the possibility. This problem asks you to calculate the hexadecimal digit nn of π\pi immediately after the hexadecimal point. For example, the hexadecimal format of π\pi is 3.243F6A8885A308D313198A2E3.243F6A8885A308D313198A2E \cdots and the 11-st digit is 22, the 1111-th one is AA and the 1515-th one is DD.

Input Format

The first line of input contains an integer TT (1T321 \le T \le 32) which is the total number of test cases. Each of the following lines contains an integer nn (1n1000001 \le n \le 100000).

Output Format

For each test case, output a single line beginning with the sign of the test case. Then output the integer nn, and the answer which should be a character in {0,1,,9,A,B,C,D,E,F}\{0, 1, \dots, 9, A, B, C, D, E, F\} as a hexadecimal number.

5
1
11
111
1111
11111
Case #1: 1 2
Case #2: 11 A
Case #3: 111 D
Case #4: 1111 A
Case #5: 11111 E