Plate
Time limit1sMemory limit512 MB
Assign labels to odd lattice points on a quadrant-by-quadrant recursive spiral, then sum labels of points on x + y = k.
- Level
Hard8 of 10
- Topics
- Math, Simulation, Divide and conquer, Matrix
- Solved
- No attempts yet
Problem
Marin spends his free time staring at the part of the coordinate plane bounded by an imaginary square whose lower left corner is at and whose upper right corner is at . In that part of the plane, Marin decided to mark the points whose two coordinates are both odd numbers. He will label the marked points with the natural numbers from to .
First he decided that the labels of all points in the first quadrant must be strictly smaller than the labels of all points in the second quadrant. Furthermore, he wants the labels of all points in the second quadrant to be smaller than the labels of all points in the third quadrant, and the labels of all points in the third quadrant to be smaller than all labels in the fourth quadrant. Then he decided that he will assign labels to the set of points of each quadrant by the same recursive procedure, with the intersection of the horizontal and vertical axes of symmetry of that quadrant's set of points taking the role of the origin.

The labels of the marked points for .
Marin now wants the sum of the labels of all marked points lying on the line .
Input
The first line contains the integers and from the problem statement (). The number will be such that at least one marked point lies on the line .
Output
Print the sum of the labels of the marked points lying on the line , modulo .