-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReachingPoints.cpp
More file actions
35 lines (32 loc) · 825 Bytes
/
ReachingPoints.cpp
File metadata and controls
35 lines (32 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <bits/stdc++.h>
using namespace std;
bool reachingPoints(int sx, int sy, int tx, int ty) {
while (true) {
if (sx == tx && sy == ty) {
return true;
}
if (sx > tx || sy > ty) {
return false;
}
if (tx > ty) {
tx -= (tx / ty) * ty;
} else {
ty -= (ty / tx) * tx;
}
}
}
bool reachingPointsOpt(int sx, int sy, int tx, int ty) {
while (sx < tx && sy < ty) {
if (tx > ty) {
tx %= ty;
} else {
ty %= tx;
}
}
return (sx == tx && sy <= ty && (ty - sy) % sx == 0) || (sy == ty && sx <= tx && (tx - sx) % sy == 0);
}
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << reachingPoints(a, b, c, d);
}