This page is still under construction.

Parts of this page are still being built. What you see may change.

Cow Gymnasts

Time limit2sMemory limit512 MB

Summary
Count circular stack-size assignments of length N (N up to 1e12) that stay unchanged after each stack falls clockwise, modulo 1e9+7.
Level

Hard8 of 10

Topics
Number theory, Math, Combinatorics, Divide and conquer
Solved
No attempts yet

Problem

The cows grew tired of farm life, sold everything they owned, and joined a traveling circus. The acts they had been given so far were easy ones: juggling torches, walking a tightrope, riding a unicycle, nothing a cow with handy hooves could not manage. The ringmaster wants a far more dramatic act for the next show.

The stage for the new act is NN platforms arranged in a circle. On each platform the cows climb onto one another's backs and build one stack, and a stack is made of at least 11 and at most NN cows. When the ringmaster gives the signal, every stack falls clockwise at the same moment. The bottom cow of a stack stays where she is, the cow directly above her moves one platform clockwise, the next cow moves two platforms, and each cow higher up moves one platform further. The stacks do not interfere with one another while they fall, so every cow lands exactly on the platform she was aimed at. The cows that land on one platform build a new stack there, and that new stack does not fall over.

The ringmaster considers the act dramatic if, after the fall, the new stack on every platform has the same size as the stack that originally stood on that platform. Call an assignment of stack sizes magical when it satisfies this condition. Count how many magical assignments there are. The count can be very large, so give it modulo 109+710^9 + 7.

Two assignments are different if there is at least one platform that is given a different number of cows.

Input

One line with a single integer NN (1≤N≤10121 \leq N \leq 10^{12}).

Output

Print, on one line, the number of magical assignments modulo 109+710^9 + 7.

Hint

For N=4N = 4 the magical assignments are (1,1,1,1)(1,1,1,1), (2,2,2,2)(2,2,2,2), (3,3,3,3)(3,3,3,3), (4,4,4,4)(4,4,4,4), (2,3,2,3)(2,3,2,3) and (3,2,3,2)(3,2,3,2), so there are six of them.

Examples3

  1. Example 1

    Input
    4
    
    Expected output
    6
    
  2. Example 2

    Input
    1
    
    Expected output
    1
    
  3. Example 3

    Input
    6
    
    Expected output
    16