#include const int Mod = 998244353; int main() { long long A, B, P, Q; scanf("%lld %lld %lld %lld", &A, &B, &P, &Q); int i; long long Z[2] = {A, (A * A + 2 * (Mod - B)) % Mod}, tmp; for (i = 2; Z[0] != Q || Z[1] != P; i++) { tmp = (A * Z[1] + (Mod - B) * Z[0]) % Mod; Z[0] = Z[1]; Z[1] = tmp; } printf("%d\n", i); fflush(stdout); return 0; }