Fast Division
Time limit2sMemory limit512 MB
Given n, let p be the smallest prime above a power tower of n twos (p(0)=2); output the remainder when the repunit with p-1 ones is divided by p.
- Level
Medium7 of 10
- Topics
- Number theory, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
Ikuta loves fast programs. Lately he has been trying to make a division program fast. But it just will not get fast, so he decided to make it fast only for inputs that are "typical by common sense." The problem Ikuta is trying to solve is as follows.
For a given nonnegative integer , find the remainder when the positive integer with digits in decimal is divided by . Here is the smallest prime greater than (with twos). Let .
Your job is to finish a program faster than Ikuta.
Input
The input is given in the following format.
The nonnegative integer of the problem input is given.
Output
Output the solution to the problem on one line.
Constraints
Each variable in the input satisfies the following constraint.