HDU 4279-Number

Source: Internet
Author: User

 

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 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.