Absolute Value Sequence
Time limit2sMemory limit128 MB
Given the first two terms of a sequence where each later term is the absolute difference of the two before it, answer up to 50 queries for S_i with i as large as 10^18.
- Level
Medium6 of 10
- Topics
- Number theory, Math, Simulation
- Solved
- No attempts yet
Problem
An infinite sequence S is defined as follows.
S_0 = firstS_1 = secondS_i = |S_{i-2} - S_{i-1}|fori >= 2
You are given first, second, and the number of queries N. For each query index i, output the value of S_i.
Input
The first line contains first, second, and the number of queries N.
Each of the next N lines contains one query. A query is an integer i, and its answer is S_i.
N is a positive integer no greater than 50. first, second, and every query index i are non-negative integers no greater than 10^18.
Output
For each query, output S_i on its own line, in the same order as the input queries.