Pagini recente » Cod sursa (job #60547) | Cod sursa (job #377048) | Cod sursa (job #1682916) | Cod sursa (job #1911779) | Cod sursa (job #465751)
Cod sursa(job #465751)
var x,a:array[1..18] of longint;
k,i,n,p,q,cod,t:longint;
c:char;
procedure testsol;
var i,t:integer;
begin
t:=0;
for i:=1 to n do
t:=(t*10+a[x[i]]) mod p;
if t=0 then inc(q);
end;
function test(k:integer):boolean;
var i:integer;
begin
test:=true;
for i:=1 to k-1 do
if x[i]=x[k] then
begin
test:=false;
break;
end;
end;
procedure back(k:integer);
var i:integer;
begin
for i:=1 to n do
begin
x[k]:=i;
if test(k) then
begin
if k=n then testsol
else back(k+1);
end;
end;
end;
begin
assign(input,'ratphu.in');reset(input);
assign(output,'ratphu.out');rewrite(output);
n:=0;
while not eoln(input) do
begin
inc(n);
read(c);
if c=' ' then break;
val(c,a[n],cod);
end;
dec(n);
read(p);
q:=0;
back(1);
write(q);
end.