#P8377. [PFOI Round1] 暴龙的火锅

[PFOI Round1] 暴龙的火锅

Background

The T-Rex loves eating hotpot.

Problem Description

Define S(x)S(x) as the sum of the digits of xx. For example, S(14)=1+4=5S(14)=1+4=5, and S(114514)=1+1+4+5+1+4=16.S(114514)=1+1+4+5+1+4=16.

Also, define fib(x)fib(x) as the xx-th term of the Fibonacci sequence. Specifically:

$$fib(1)=fib(2)=1,\ fib(x)=fib(x-1)+fib(x-2)\ (x\ge 3).$$

Given nn, compute the value of the following expression, where mod9\bmod 9 means taking the remainder modulo 99:

$$(S(fib(1))+S(fib(2))+S(fib(3))+...+S(fib(n))) \bmod 9.$$

Input Format

The first line contains an integer TT.

Then follow TT queries, each containing one integer nn.

Output Format

Output TT lines, each line containing one integer representing the answer.

3
7
14
114514
6
5
8

Hint

[Sample Explanation]

For the first query, n=7n=7, the answer is:

$$\begin{aligned} & \ \ \ \ \ (S(fib(1))+S(fib(2))\ldots+S(fib(6))+S(fib(7)))\bmod 9 \\ & =(1+1+2+3+5+8+(1+3))\bmod 9 \\ & =6. \end{aligned}$$

[Constraints]

This problem uses bundled testdata.

  • Subtask 1 (10 pts): T=1, n10\texttt{Subtask 1 (10 pts): } T=1,\ n\le 10;
  • Subtask 2 (30 pts): T=102, n103\texttt{Subtask 2 (30 pts): } T=10^2,\ n\le 10^3;
  • Subtask 3 (60 pts): \texttt{Subtask 3 (60 pts): } no special constraints.

For 100%100\% of the data, 1T105, 1n1061\le T\le 10^5,\ 1\le n\le 10^6.

Translated by ChatGPT 5