From 3e48da5f1520416212a98d617be58ed31a66476f Mon Sep 17 00:00:00 2001 From: hanyixuanten <105723997+hanyixuanten@users.noreply.github.com> Date: Wed, 15 Jul 2026 16:41:57 +0800 Subject: [PATCH] new file: P1516.cpp --- P1516.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 P1516.cpp diff --git a/P1516.cpp b/P1516.cpp new file mode 100644 index 0000000..012982e --- /dev/null +++ b/P1516.cpp @@ -0,0 +1,29 @@ +#include +#define int long long +int exgcd(int a, int b, int &x, int &y) +{ + if (b == 0) + { + x = 1, y = 0; + return a; + } + int ans = exgcd(b, a % b, y, x); + y -= a / b * x; + return ans; +} +signed main() +{ + // freopen("frog.in", "r", stdin); + // freopen("frog.out", "w", stdout); + int a, b, x, y, n, m, l; + scanf("%lld%lld%lld%lld%lld", &a, &b, &m, &n, &l); + int ans = exgcd(m - n, l, x, y), mod = abs(l / ans); + if ((b - a) % ans) + { + printf("Impossible\n"); + return 0; + } + x = (x * ((b - a) / ans) % mod + mod) % mod; + printf("%lld\n", x); + return 0; +} \ No newline at end of file