Advertisement
Guest User

forest4trees

a guest
Dec 6th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef unsigned long long BIGNUM;
  5. typedef char BOOL;
  6.  
  7. BIGNUM gcd(BIGNUM a, BIGNUM b);
  8. BOOL insquare(BIGNUM xpos, BIGNUM ypos, BIGNUM x1, BIGNUM y1, BIGNUM x2, BIGNUM y2);
  9.  
  10. int main(int  argc, char **argv)
  11. {
  12.     BIGNUM b_x, b_y, x1, y1, x2, y2;
  13.     BIGNUM xstep, ystep;
  14.     BIGNUM xpos = 0;
  15.     BIGNUM ypos = 0;
  16.     BIGNUM div;
  17.     scanf("%ld%ld%ld%ld%ld%ld", &b_x, &b_y, &x1, &y1, &x2, &y2);
  18.     div = gcd(b_x, b_y);
  19.     xstep = b_x / div;
  20.     ystep = b_y / div;
  21.  
  22.     while (1) {
  23.         xpos += xstep;
  24.         ypos += ystep;
  25.         if (xpos >= b_x) {
  26.             printf("Yes\n");
  27.             break;
  28.         }
  29.         else if (insquare(xpos, ypos, x1, y1, x2, y2)) {
  30.             xpos += ((x2 - x1) / div) * xstep;
  31.             ypos += ((y2 - y1) / div) * ystep;
  32.             continue;
  33.         }
  34.         else {
  35.             printf("No\n%ld %ld\n", xpos, ypos);
  36.             break;
  37.         }
  38.     }
  39.     return 0;
  40. }
  41.  
  42. BOOL insquare(BIGNUM xpos, BIGNUM ypos, BIGNUM x1, BIGNUM y1, BIGNUM x2, BIGNUM y2)
  43. {  
  44.     return (xpos >= x1 && xpos <= x2 &&
  45.             ypos >= y1 && ypos <= y2);
  46. }
  47.  
  48. BIGNUM gcd(BIGNUM a, BIGNUM b)
  49. {  
  50.     BIGNUM r = a % b;
  51.     return (r ? gcd(b, r) : b);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement