Welcome
题目描述
输入
第一行三个整数,n,m和T。
第二行n个数,第i个数表示ai。
第三行m个数,第i个数表示bi。
输出
输出一个数,答案对T取余数的结果。
样例输入
3 2 998244353
2 2 6
3 3
样例输出
80
范围
浅析
很容易想到这道题需要用 Legendre 定理
根据定理我们可以很容易想到在读入的时候进行处理,将这些数分解后的指数存到对应质数的数组里,所以我们需要用O(n)的时间将质数预处理出来,然后用qkpow算出答案输出即可。
代码
#include<cstdio>
#define LL long long
#define M 100000
#define reg register
inline void read(int &x){
int f = 1;
x = 0;
char s = getchar();
while (s < '0' || s > '9'){
if (s == '-')
f = -1;
s = getchar();
}
while (s >= '0' && s <= '9'){
x = x * 10 + s - '0';
s = getchar();
}
x *= f;
}
int n,m,Factor[M + 5],T,Prime[M + 5],tot;
LL Ans = 1;
bool vis[M + 5];
void Euler(){
for (reg int i = 2;i <= M; ++ i){
if ( ! vis[i])
Prime[ ++ tot] = i;
for (reg int j = 1;j <= tot; ++ j){
int x = Prime[j] * i;
if (x > M)
break;
vis[x] = true;
if ( ! (i % Prime[j]))
break;
}
}
}
void Fac(int n,int f){
for (reg int i = 1;i <= tot && Prime[i] <= n; ++ i){
LL sum = Prime[i];
while (sum <= n){
Factor[i] += f * n / sum;
sum *= Prime[i];
}
}
return ;
}
LL qkpow(int n,int y){
LL ans = 1;
while(y){
if (y % 2)
ans *= n % T;
n = n * n % T;
y /= 2;
}
return ans;
}
void Init(){
Euler();
read(n),read(m),read(T);
for (reg int i = 1;i <= n; ++ i){
int a;
read(a);
Fac(a,1);
}
for (reg int i = 1;i <= m; ++ i){
int a;
read(a);
Fa