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}\)
Explanation
For \(n=3\), the only possible over-optimistic permutation is \(\{3,1,2\}\).
Code Editor
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
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
1.Non-Fibo
Points:30
8 votes
Tags:
MathematicsMediumOpenApprovedNumber Theory
Points:30
Tags:
MediumLinear AlgebraMatrix ExponentiationAlgorithmsMathematicsOpenApproved
Points:30
Tags:
Medium
Editorial
Login to unlock the editorial
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
Results
Custom Input
Run your code to see the output