样例输入
4 3
1
2
3
2
11
23
100
样例输出
1
0
23
提示
var
i,n,m,nu,j,k,b,t:longint;
ans,s:int64;
x:array[0..333,0..333] of int64;
num,a,p,y:array[0..333] of int64;
flag:boolean;
function check(u:longint):boolean;
var
i:longint;
begin
for i:=2 to trunc(sqrt(u)) do
if u mod i=0 then exit(false);
exit(true);
end;
begin
readln(n,m);
i:=2;
while nu<n do
begin
if check(i) then begin nu:=nu+1; p[nu]:=i; end;
i:=i+1;
end;
for i:=1 to n do
for j:=1 to n do
begin
s:=1;
for k:=1 to i-1 do
s:=s*p[k] mod p[j];
x[i,j]:=s;
end;
flag:=true;
for i:=1 to n do
begin
readln(a[i]);
if a[i]<>0 then flag:=false;
end;
if flag then
begin
for i:=1 to m do
begin
readln(b);
s:=1;
for j:=1 to n do
s:=s*p[j] mod b;
writeln(s);
end;
exit;
end;
for i:=1 to n do
begin
s:=0;
for j:=1 to i-1 do
s:=(s+num[j]*x[j,i]) mod p[i];
while s<>a[i] do
begin
num[i]:=num[i]+1;
s:=(s+x[i,i]) mod p[i];
end;
end;
for t:=1 to m do
begin
readln(b);
for i:=1 to n do
begin
s:=1;
for j:=1 to i-1 do
s:=s*p[j] mod b;
y[i]:=s;
end;
ans:=0;
for i:=1 to n do
ans:=(ans+num[i]*y[i]) mod b;
writeln(ans);
end;
end.