Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- #include <bits/stdc++.h>
- int EET(int a,int b,int *x,int *y) {
- if(b==0) {
- *x=1;
- *y=0;
- return a;
- }
- int x1;
- int y1;
- int d = EET(b,a%b,&x1,&y1);
- *x = y1;
- *y = x1-(a/b)*y1;
- return d;
- }
- int main() {
- int a,b,c,x1,x2,y1,y2;
- cin>>a>>b>>c>>x1>>x2>>y1>>y2;
- c*=-1;
- //ax + by = c
- int x;
- int y;
- int d = EET(a,b,&x,&y);
- if(c%d!=0) {cout<<0<<endl; return 0; }
- int xf = (x*c)/d;
- int yf = (y*c)/d;
- if (a < 0) xf= -xf;
- if (b < 0) yf = -yf;
- int xff=xf;
- int yff=yf;
- //shift by b/d,-a/d
- int count=0;
- //right shift
- if(xff<=x2&&xff>=x1&&yff<=y2&&yff>=y1) count++;
- while(xff<=x2&&yff>=y1) {
- if(xff+b/d<=x2&&yff-a/d>=y1){
- xff+=b/d;
- yff-=a/d;
- count++;
- } else { break; }
- }
- // count--;
- xff=xf;
- yff=yf;
- while(xff>=x1&&yff<=y2) {
- if(xff-b/d>=x1&&yff+a/d<=y2){
- xff-=b/d;
- yff+=a/d;
- count++;
- } else { break; }
- }
- // count--;
- cout<<count<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement