report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
Digits - FlandreOJ: Flandre Online Judge

Digits

Time limit: 1000 ms
Memory limit: 256 MB
The n-th Fib number can be calculated using the following formula: $fib(n) = \begin{cases} a & \text{if } n = 1 \\\\ b & \text{if } n = 2 \\\\ fib(n-1) + fib(n-2) & \text{if } n \ge 3 \end{cases}$ **Task**: Given four positive integers $a$, $b$, $L$, and $R$ $(1 \leq a, b, L, R \leq 10^{18})$, find the last digit of $f(n)$. #### Input - The first line contains a positive integer $T$ $(1 \leq T \leq 10^5)$, which is the number of data sets. - The following $T$ lines each contain four positive integers $a$, $b$, $L$, and $R$. #### Output - Print $T$ lines, each containing a single digit, which is the last digit of $f(n)$ for the corresponding input data set. #### Example Input: ``` 2 1 1 1 3 1 1 3 3 ``` Output: ``` 4 2 ``` #### Subtasks - **Subtask 1 (40 points)**: $L \le R \leq 10^6$. - **Subtask 2 (30 points)**: $R - L \leq 10^6$. - **Subtask 3 (30 points)**: No additional constraints.
The 2023 Youth Informatics Contest - Central Regional Group B
Digits
Set
Set of three numbers
The 2023 Youth Informatics Contest - Central Regional Group C2
Digits
Set of three numbers
Gifting
Topic
Others
Rating 1800
Solution (0) Solution