BZOJ5027: mathematical questions, bzoj5027 mathematical questions

Source: Internet
Author: User

BZOJ5027: mathematical questions, bzoj5027 mathematical questions

Time Limit: 10 Sec Memory Limit: 256 MB
Submit: 140 Solved: 48
[Submit] [Status] [Discuss] Description: returns a, B, c, x1, x2, y1, y2. Obtain the conditions that meet the requirements of ax + by + c = 0, and x in [x1, x2], y in [y1, y2] How many pairs of integer solutions are there?

 

The first line of Input contains seven integers, a, B, c, x1, x2, y1, y2, which are separated by spaces. The absolute values of a, B, c, x1, x2, y1, y2 cannot exceed 10 ^ 8.

 

How many pairs of Output integer solutions?

 

Sample Input1 1-3 0 4 0 4 Sample Output4HINT Source It can be seen at a glance that it is Europe Expansion Process the upper and lower boundary using the general formula of the expanded Europe Region Pay attention to the judgment in special cases Note:

Must first multiply and then divide

No error occurred when calling the MPs for one night and taking n groups of data ..

 

# Include <iostream> # include <cstdio> # include <cmath> # define LL long using namespace std; const ll maxn = 1e6 + 10; LL a, B, c, x1, x2, yy1, y2, x, y; LL exgcd (LL a, LL B, LL & x, LL & y) {if (B = 0) {x = 1, y = 0; return a;} LL r = exgcd (B, a % B, x, y), tmp; tmp = x, x = y, y = tmp-a/B * y; return r;} LL min (LL a, LL B) {return a <B? A: B;} LL max (LL a, LL B) {return a> B? A: B;} int main () {cin> a> B> c> x1> x2> yy1> y2; c =-c; if (a = 0 & B = 0) {if (c = 0) {printf ("% lld", (LL) (x2-x1 + 1) * (y2-yy1 + 1); return 0;} else {printf ("0"); return 0 ;}} if (a = 0) {if (c % B) {printf ("0"); return 0;} if (c/B> = yy1 & c/B <= y2) {printf ("% lld ", x2-x1 + 1); return 0;} else {printf ("0"); return 0 ;}}if (B = 0) {if (c %) {printf ("0"); return 0;} if (c/a> = x1 & c/a <= x2) {printf ("% lld ", y2-yy1 + 1); return 0;} else {printf ("0"); return 0 ;}} LL r = exgcd (a, B, x, y ); B = B/r; a =-a/r; // use the formula to construct the incremental if (c % r) {printf ("0"); return 0 ;} x = x * c/r; y = y * c/r; LL xlower, xupper, ylower, yupper; if (B> 0) xlower = ceil (double) (x1-x)/B), xupper = floor (double) (x2-x)/B); if (B <0) xlower = ceil (double) (x2-x) /B), xupper = floor (double) (x1-x)/B); if (a> 0) ylower = ceil (double) (yy1-y)/), yupper = floor (double) (y2-y)/a); if (a <0) ylower = ceil (double) (y2-y)/), yupper = floor (double) (yy1-y)/a); LL ans = max (0, min (xupper, yupper)-max (xlower, ylower) + 1 ); printf ("% lld", ans); return 0;} // 1 5-3-123 40-567 41

 

Related Article

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.