ll qpow(ll base, ll p){ if (p <= 0) return1; ll res = qpow(base, p >> 1); res = res * 1ll * res % C; if (p & 1) res = res * 1ll * base % C; return res; }
intmain(){ int kase = 0; while (cin >> C >> k1 >> b1 >> k2) { printf("Case #%d:\n", ++kase); int ans = 0; for (ll a = 1; a < C; a++) { ll b = C - qpow(a, k1 + b1); if ((qpow(a, (k1 << 1) + b1) + qpow(b, k2 + 1)) % C == 0) { printf("%lld %lld\n", a, b); ans++; } } if (ans == 0) printf("-1\n"); } }