説明
OJを参照してください。
溶液
まず暴力の50分を思ったが、また、すべての素数に対して個別に答えを求めて、そして最終的に結果を乗算し、ぶら下がっていると思います。
ポジティブ・ソリューションズ中国の剰余定理は、首相の各要件のために分離することができます。
\((X ^ MX)\) %の\(N-0 = \)
ので\(\ N-)異なる組成の素数複数の、我々は、に分解中国の剰余定理を使用することができる\(C \)式を。
そして、取得し\(^ X-mx≡0(P-MOD〜)\)(\ (のC \)方程式)
我々は最後の答えにそれを取る、追求する暴力のための50個のポイントごとです。
時間\(O(C * T * T *関数logm)\)、80分。
あるので、\は(\を記録)、我々は、最適化を検討してください。
ふるいの生成物(オイラーをふるい)、我々は近づくことができる(\ O(N))\を得る\(1 \)を〜\(N- \)\(m個\) %の電力番目、\(N- \)重要性の下で。
素数直接\(KSM \)得\(X ^ Mの\) 、およびそれらを併用してもよい数は素数であり、\(Y \)の値と\(X / Yの\)乗じた値。
このような排除\(\を記録)、ACことができます。
コード
#include <cstdio>
#include <cstring>
#define N 51
#define ll long long
#define mo 998244353
#define mem(x, a) memset(x, a, sizeof x)
#define fo(x, a, b) for (int x = a; x <= b; x++)
#define fd(x, a, b) for (int x = a; x >= b; x--)
using namespace std;
int id, T, c, m, n, ans, s1;
int kz[10010], phi[N], pri[10010];
inline int read()
{
int x = 0; char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return x;
}
int ksm(int x, int y)
{
int s = 1;
while (y)
{
if (y & 1) s = s * x % n;
x = x * x % n; y >>= 1;
}
return s;
}
int main()
{
freopen("division.in", "r", stdin);
freopen("division.out", "w", stdout);
id = read();
T = read();
while (T--)
{
c = read(), m = read();
fo(i, 1, c) phi[i] = read();
ans = 1;
fo(i, 1, c)
{
s1 = 1; n = phi[i];
fo(ii, 2, n) kz[ii] = 0;
pri[0] = 0;
fo(ii, 2, n)
{
if (! kz[ii]) kz[ii] = ksm(ii, m), pri[++pri[0]] = ii;
for (int j = 1; pri[j] * ii <= n; j++)
{
kz[pri[j] * ii] = kz[pri[j]] * kz[ii] % n;
if (ii % pri[j] == 0) break;
}
if (kz[ii] == ii % n) s1++;
}
ans = (ll)ans * s1 % mo;
}
printf("%d\n", ans);
}
return 0;
}