#P17074. [ICPC 2017 Shenyang R] New Self-describing Sequence

[ICPC 2017 Shenyang R] New Self-describing Sequence

Problem Description

Let a1,a2,⋯a_1, a_2, \cdots be an integer sequence beginning with a1=1a_1 = 1. For n≥1n \ge 1, an+1a_{n+1} is the sum of ana_n and the sum of digits of ana_n. That’s why we name the sequence a new Self-describing sequence.

The sequence starts with 1,2,4,8,16,23,28,38,49,⋯1, 2, 4, 8, 16, 23, 28, 38, 49, \cdots and we also define the prefix sum sn=a1+a2+⋯+ans_n = a_1 + a_2 + \cdots + a_n. For given positive integer nn, find ana_n and sns_n.

Input Format

The first line of input consists an integer TT (T≤32768T \le 32768), indicating the total number of test cases. Each of the following TT lines provides an integer nn (n≤1017n \le 10^{17}).

Output Format

For each test case output its case label first. Then for given nn, output ana_n and sns_n. Since the prefix sum is large, you only need to output sn mod 1000000009s_n \bmod 1000000009. However you should output ana_n as its exact value.

7
6
66
666
6666
66666
123456789
31415926535897932
Case #1: 23 54
Case #2: 752 20862
Case #3: 10949 3407733
Case #4: 136193 441127485
Case #5: 1698899 717710112
Case #6: 5061289531 990040993
Case #7: 2508156610654066874 660828136