cincout

dioff

Nov 1st, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. pr<int, int> gcd(int a, int b, int xa, int ya, int xb, int yb)
  2. {
  3. if (b == 0)
  4. {
  5. return {xa, ya};
  6. }
  7. int k = a / b;
  8. return gcd(b, a % b, xb, yb, xa - k * xb, ya - k * yb);
  9. }
  10.  
  11. bool find_any_solution(int a, int b, int c, int &x0, int &y0) {
  12. int d = __gcd(a, b);
  13. if (c % d) {
  14. return 0;
  15. }
  16. auto solve = gcd(abs(a), abs(b), 1, 0, 0, 1);
  17. x0 = solve.first;
  18. y0 = solve.second;
  19. x0 *= c / d;
  20. y0 *= c / d;
  21. if (a < 0) x0 *= -1;
  22. if (b < 0) x0 *= -1;
  23. return 1;
  24. }
  25.  
  26. void shift_solution(int &x, int &y, int a, int b, int cnt) {
  27. x += cnt * b;
  28. y -= cnt * a;
  29. }
Add Comment
Please, Sign In to add comment