The Enormous Sequence
Time limit2sMemory limit128 MB
Define a_n by summing every nonempty subset sum of the first n-1 terms, then answer queries about gcd, 2-adic valuation of lcm, prefix sums, or a single term for various starting values.
- Level
Hard9 of 10
- Topics
- Math, Number theory, Combinatorics, Prefix sum
- Solved
- No attempts yet
Problem
Fibonacci numbers grow fast. Taekhee wrote them on paper all the way to the millionth term and still was not satisfied, so he defined a sequence of his own that grows much faster.
The first term is . With , the next term is given by
In other words, for every way of choosing at least one term among through , take the sum of the chosen terms, and is the total of all those sums.
For the first few terms are
Taekhee prepared questions about this sequence. Each question comes with its own first term , so each question is about its own sequence. Write a program that answers all of them.
Input
The first line contains the number of questions . ()
Each of the next lines contains one question in one of the four forms below.
1 a1 i j(, ): in the sequence whose first term is , what is the greatest common divisor of and ?2 a1 i j(, ): in the sequence whose first term is , let be the least common multiple of and . That value is far too large, so the question asks for the largest integer such that is an integer.3 a1 i j(, ): in the sequence whose first term is , what is ? A question of this form always satisfies .4 a1 k(, ): in the sequence whose first term is , what is ?
Output
Print lines. On each line print the answer to the corresponding question modulo 1,000,000,007, in the order the questions are given.