rt,暴力可过。
#include <cstring>
#include <iostream>
using namespace std;
const int N = 5e4 + 10;
int n, a, b;
bool vis[N];
void run()
{
scanf("%d%d%d", &n, &a, &b);
memset(vis + 1, 0, n);
if (b == 1)
{
puts("0");
return;
}
vis[1] = true;
for (int i = a % n, j = 1; !vis[i]; i = 1ll * i * a % n, j++)
{
if (vis[i])
{
puts("Couldn't Produce!");
return;
}
if (i == b)
{
printf("%d\n", j);
return;
}
vis[i] = true;
}
puts("Couldn't Produce!");
}
int main()
{
int T = 1;
scanf("%d", &T);
while (T--)
run();
}