Jason's Theorem

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 0.5s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Baba Jason was playing around with his slide rules one morning and discovered an important mathematical property:

\displaystyle \text{If }x=x_{x}^{x} \text{ then } x=x_{x_{x}^{x}}^{x_{x}^{x}}

Jason brought the discovery to Nathan, his math professor. Nathan was so impressed by the discovery that he convinced Jason to co-publish it in arXiv. Before Jason could publish the paper, Nathan informs him that mathematicians are very skeptical people, and will want to see more iterations in the sequence before they accept it.

The sequence is written in a markdown language known as \LaTeX, and the sequences are as such

(0) x=x
(1) x=x_{x}^{x}
(2) x=x_{x_{x}^{x}}^{x_{x}^{x}}
(3) x=x_{x_{x_{x}^{x}}^{x_{x}^{x}}}^{x_{x_{x}^{x}}^{x_{x}^{x}}}
(4) x=x_{x_{x_{x_{x}^{x}}^{x_{x}^{x}}}^{x_{x_{x}^{x}}^{x_{x}^{x}}}}^{x_{x_{x_{x}^{x}}^{x_{x}^{x}}}^{x_{x_{x}^{x}}^{x_{x}^{x}}}}

Jason quickly realizes that this will take a really long time to type, so he asks you how many keystrokes it will take to complete the N^{th} iteration. Please help him!

Input Specification

A single integer N.

Output Specification

Print the number of keystrokes Jason needs to type modulo 10^9+7.


0 \le N \le 2^{63}-1

Sample Input 1


Sample Output 1


Sample Input 2


Sample Output 2


Sample Input 3


Sample Output 3


Sample Input 4


Sample Output 4


Sample Input 5


Sample Output 5


Sample Explanations

The examples are given in the problem description.


There are no comments at the moment.