atcoder#AGC039C. [AGC039C] Division by Two with Something
[AGC039C] Division by Two with Something
Score : points
Problem Statement
Given are integers and . For each integer between and (inclusive), find the answer to the following question, then compute the sum of all those answers, modulo .
- Let us repeat the following operation on the integer . Operation: if the integer is currently odd, subtract from it and divide it by ; otherwise, divide it by and add to it. How many operations need to be performed until returns to its original value? (The answer is considered to be if never returns to its original value.)
Constraints
- is given in binary and has exactly digits. (In case has less than digits, it is given with leading zeroes.)
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the sum of the answers to the questions for the integers between and (inclusive), modulo .
3
111
40
For example, for , the operation changes as follows: . Therefore the answer for is .
6
110101
616
30
001110011011011101010111011100
549320998