Optimistic Permutations
Practice
0 (0 votes)
Problem
10% Success 183 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Let \(p_1, p_2, ..., p_n\) be a permutation of \(1,2, ...,n\).

An optimistic permutation follows \(p_i > i-2 \, \forall \, i \in [1, n]\).

An over-optimistic permutation has the following properties:

  • It is optimistic.
  • There exists atleast one \(i \,(i \in [1, n])\) such that  \(p_i \geq i+2 \).

Given \(n\), find the count of all over-optimistic permutations modulo \(10^9+7\).

Input:

The first line contains \(T \) - the number of testcases, followed by T lines each containing one integer \(n\).

Output:

For each testcase print the answer on a newline.

Constraints:

  • \(1 \leq T \leq 500000\)
  • \(1\leq n \leq 10^{18}\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
Tags:
Medium
Points:30
9 votes
Tags:
Linear AlgebraDynamic ProgrammingAlgorithmsMatrix ExponentiationMath
Points:30
1 votes
Tags:
Linear AlgebraDynamic ProgrammingMatrix ExponentiationMediumMathematics