Advertisement
Singasking

Untitled

Jan 21st, 2023
1,128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. using namespace std;
  2. #include <bits/stdc++.h>
  3. int EET(int a,int b,int *x,int *y) {
  4.     if(b==0) {
  5.         *x=1;
  6.         *y=0;
  7.         return a;
  8.     }
  9.     int x1;
  10.     int y1;
  11.     int d = EET(b,a%b,&x1,&y1);
  12.     *x = y1;
  13.     *y = x1-(a/b)*y1;
  14.     return d;
  15. }
  16. int main() {
  17.     int a,b,c,x1,x2,y1,y2;
  18.     cin>>a>>b>>c>>x1>>x2>>y1>>y2;
  19.     c*=-1;
  20.     //ax + by = c
  21.    
  22.     int x;
  23.     int y;
  24.     int d = EET(a,b,&x,&y);
  25.     if(c%d!=0) {cout<<0<<endl; return 0; }
  26.     int xf = (x*c)/d;
  27.     int yf = (y*c)/d;
  28.       if (a < 0) xf= -xf;
  29.     if (b < 0) yf = -yf;
  30.     int xff=xf;
  31.     int yff=yf;
  32.     //shift by b/d,-a/d
  33.     int count=0;
  34.     //right shift
  35.     if(xff<=x2&&xff>=x1&&yff<=y2&&yff>=y1) count++;
  36.     while(xff<=x2&&yff>=y1) {
  37.   if(xff+b/d<=x2&&yff-a/d>=y1){
  38.     xff+=b/d;
  39.     yff-=a/d;
  40.     count++;
  41.   }  else { break; }
  42.     }
  43.   //  count--;
  44.     xff=xf;
  45.     yff=yf;
  46.    
  47.    
  48.       while(xff>=x1&&yff<=y2) {
  49.  if(xff-b/d>=x1&&yff+a/d<=y2){
  50.     xff-=b/d;
  51.     yff+=a/d;
  52.     count++;
  53.  } else { break; }
  54.        
  55.     }
  56.   //  count--;
  57.     cout<<count<<endl;
  58.     return 0;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement