fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. // Funkcja obliczająca NWD dwóch liczb
  6. int gcd(int a, int b) {
  7. while (b != 0) {
  8. int t = b;
  9. b = a % b;
  10. a = t;
  11. }
  12. return abs(a);
  13. }
  14.  
  15. int main() {
  16. int K, N;
  17. int x1, y1, x2, y2;
  18. int dx, dy,g,q;
  19. // Wczytywanie danych
  20. cin >> q;
  21. for(int i = 0; i < q; i++){
  22. cin >> K >> N;
  23. cin >> x1 >> y1 >> x2 >> y2;
  24.  
  25. // Obliczanie różnic współrzędnych
  26. dx = abs(x2 - x1);
  27. dy = abs(y2 - y1);
  28.  
  29. // Obliczanie NWD dla K i N
  30. int g = gcd(K, N);
  31. cout << dx << " " << dy << " " << g << "\n";
  32. // Sprawdzanie, czy można przejść z (x1, y1) do (x2, y2)
  33. if (dx % g == 0 && dy % g == 0) {
  34. cout << "TAK" << endl;
  35. } else {
  36. cout << "NIE" << endl;
  37. }
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5300KB
stdin
3
2 1 0 0 3 3
1 1 1 1 1 2
1 0 2 3 4 6
stdout
3 3 1
TAK
0 1 1
TAK
2 3 1
TAK