建议降黄
查看原帖
建议降黄
475403
Redshift_Shine楼主2024/8/14 16:19

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();
}
2024/8/14 16:19
加载中...