#P1676. 「CMOI R0」Parallel Universe Shifter / Lattices in Circle

「CMOI R0」Parallel Universe Shifter / Lattices in Circle

Background

The original "[USACO05FEB] Aggressive Cows G" can be found at P1824.

$$\text{Answer}=\pi n^2+\mathrm O(n^{\frac{517}{824}}).$$

$\small\color{white}/35^{\text{th}}\text{Problem by AtC}.$

Problem Description

Find the number of integer lattice points whose distance to the origin is at most nn (1n1012)(1\leq n\leq 10^{12}).

Input Format

One line with one positive integer nn.

Output Format

One line with one positive integer, the answer. Note that it may be greater than 2642^{64}.

1
5
2
13
5
81
19
1129
100
31417
30000
2827432965
10000000
314159265350589
500000000
785398163397389961
16000000000
804247719318986163169
700000000000
1539380400258998682200449

Hint

Explanation for Sample 11

The 55 points that satisfy the condition are (0,0),(1,0),(0,1),(0,1),(1,0)(0,0),(1,0),(0,1),(0,-1),(-1,0).

Constraints

Subtask\text{Subtask} Special Constraints\text{Special Constraints} Time Limit\text{Time Limit} Points\text{Points}
11 1n2×1031\leq n\leq 2\times 10^3 0.25s0.25\text s 11
22 104n10710^4\leq n\leq 10^7 1s1\text s 44
33 108n10910^8\leq n\leq 10^9 1010
44 109n101010^9\leq n\leq 10^{10} 3s3\text s 1515
55 1010n101110^{10}\leq n\leq 10^{11} 4s4\text s 3030
66 1011n101210^{11}\leq n\leq 10^{12} 4040

Translated by ChatGPT 5