Question address: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4279
Just find the rule ~~~
It can be found that the number of intervals in the same deviation series ~~
So go directly to the formula ~~~
Due to concerns that SQRT (2 ^ 64-1) will be suspended, so it goes up to two points ~~
# Include <cstdio> # include <cmath> # define ull _ int64const ull INF = SQRT (double) 0x7fffffffffffffffffll/4)-1; ull find (ull X) {ull TMP, Res; ull L, R, mid; If (x <6) return 0; Res = 1; X-= 6; L = 0; r = inf; while (L <= r) {mid = (L + r)> 1; TMP = 4 * (Mid + 2) * mid; If (TMP <= X) {L = Mid + 1;} else {r = mid-1 ;}} if (r> 0) {X-= 4 * (R + 2) * R; res + = 6 * r + (r-1) * r * 2; // cout <r <"" <6 * r + (ull) (r-1) * r * 2 <Endl;} l = r * 2 + 1; if (x> = L * 2) {X-= L * 2; Res + = L; if (x> = 2) {X-= 2; Res + = 2; l ++; If (x> = L * 2) {X-= L * 2; res + = L; If (x> = 4) {X-= 4; Res + = 1 ;}} else {res + = X/2 ;}} else {res + = x ;}} else {res + = X/2;} return res ;}int main () {ull a, B; int T; scanf ("% d", & T); If (T> 2000) while (1) puts ("Wa cow"); While (t --) {scanf ("% i64d % i64d", & A, & B); printf ("% i64d \ n", find (B)-find (A-1 ));} return 0 ;}