voidinsert(int x, int y) { int k = x % MOD; hs[top] = x; id[top] = y; next[top] = head[k]; head[k] = top++; } intfind(int x) { int k = x % MOD; for (int i = head[k]; i != -1; i = next[i]) if (hs[i] == x) return id[i]; return-1; } intBSGS(int a, int b, int n) { memset(head, -1, sizeof(head)); top = 1; if (b == 1) return0; int m = sqrt(n * 1.0), j; longlong x = 1, p = 1; for (int i = 0; i < m; i++, p = p * a % n) insert(p * b % n, i); for (longlong i = m; ; i += m) { if ((j = find(x = x * p % n)) != -1) return i - j; if (i > n) break; } return-1; } intmain() { int a, b, n; while (~scanf("%d%d%d", &n, &a, &b)) { int ans = BSGS(a, b, n); if (ans == -1) printf("no solution\n"); else printf("%d\n", ans); } }