diff --git a/jiyunpar/math/6064.cpp b/jiyunpar/math/6064.cpp new file mode 100644 index 0000000..32e9a71 --- /dev/null +++ b/jiyunpar/math/6064.cpp @@ -0,0 +1,46 @@ +#include + +using namespace std; + +int gcd(int a, int b) +{ + if (b == 0) + return (a); + return (gcd(b, a % b)); +} + +int lcm(int a, int b) +{ + return (a / gcd(a, b) * b); +} + +int solved(int m, int n, int x, int y) +{ + if (x == m) + x = 0; + if (y == n) + y = 0; + int l = lcm(m, n); + for (int i = x; i <= l; i += m) + { + if (i == 0) + continue; + if (i % n == y) + return (i); + } + return (-1); +} + +int main(void) +{ + ios::sync_with_stdio(0); + cin.tie(0); + int t, n, m, x, y; + cin >> t; + for (int i = 0; i < t; ++i) + { + cin >> m >> n >> x >> y; + cout << solved(m, n, x, y) << '\n'; + } + return (0); +} \ No newline at end of file diff --git a/jiyunpar/math/gcd.cpp b/jiyunpar/math/gcd.cpp new file mode 100644 index 0000000..8eef934 --- /dev/null +++ b/jiyunpar/math/gcd.cpp @@ -0,0 +1,25 @@ +#include +#include + +using namespace std; + +int gcd(int a, int b) +{ + if (b == 0) + return (a); + return (gcd(b, a % b)); +} + +int lcm(int a, int b) +{ + return (a / gcd(a, b) * b); +} + +int main(void) +{ + int a, b, ans; + cin >> a >> b; + ans = lcm(a, b); + cout << ans; + return (0); +} \ No newline at end of file