404507: GYM101521 K Lattice Points

Memory Limit:64 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

K. Lattice Pointstime limit per test1 secondmemory limit per test64 megabytesinputstandard inputoutputstandard output

Jeremy loves geometry and counting. Unsurprisingly, he wants to do both at the same time!

On a Cartesian coordinate plane, Jeremy now draws a circle of radius R, centered at the origin. He wants to know how many lattice points have a distance no further than D units from the circumference of the circle he has just drawn. A lattice point on the Cartesian coordinate plane is a point with integer coordinates.

Jeremy can only draw small circles and count the points one by one. When R and D get large, he has no idea what the answer is. Help Jeremy!

Input

The first and only line of input consists of two integers R and D.

For all input, 1 ≤ R ≤ 500000, 0 ≤ D ≤ 500000.

Output

Output one single integer, the number of lattice points no further than D units from the circumference of a circle of radius R and centered at the origin.

Hint: Use 64-bit integers (Pascal: int64, C++: long long).

ExamplesInput
3 1
Output
40
Input
2 4
Output
113
Input
123456 78901
Output
122406524248
Note

Pictured is sample 1. The small dots indicate the lattice points that should be counted towards the answer.

加入题单

算法标签: