Cow Gymnasts
Time limit2sMemory limit512 MB
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 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 and at most 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 .
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 ().
Output
Print, on one line, the number of magical assignments modulo .
Hint
For the magical assignments are , , , , and , so there are six of them.