Zoj3629 Treasure Hunt IV
Idea: Find the rule and find the number that meets the requirements
[0, 1)
[4, 9)
[16, 25)
[36,49)
............
[N ^ 2, (n + 1) ^ 2)
We can find that the range from n ^ 2 to (n + 1) ^ 2 (n is an even number) is the number that meets the requirements, and then find that (n + 1) * (n + 1)-a series of n * n is a 4-difference series. We need to set the range [a, B] to meet the requirements, then you only need to use B before the number that meets the requirements minus the number that meets the requirements in the A-1 .....
WA at the beginning, and then we found that the % I64d used in input and output should be changed to % lld, which is a tragedy ......
Code:
# Include
# Include
# Include
# Include
Using namespace std; typedef long LL; LL f (LL x) // calculates the required number between 0 and x, 1 {if (x =-1) return 0; LL a = sqrt (x); LL sum = 0; if (a * a = x) {LL n = (a + 1)/2; sum = n + n * (n-1) * 2; if (a % 2 = 0) {sum ++ ;}} else if (a *