Code: Select all
Program p10093;
Const Abc = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
Var DivRes : Array[1..62]of integer;
i,MinDR,j : Integer;
ch : Char;
begin
While Not Eof(InPut) Do begin
for i:=1 to 62 do DivRes[i]:=0;
MinDR:=2;
While True do begin
if (Eof(InPut))or(Eoln(InPut)) then break;
Read(ch);
if Pos(ch,Abc)>0 then j:=Pos(ch,Abc)-1 else MinDr:=100;
if j+1>MinDR then MinDR:=j+1;
for i:=MinDR to 62 do
DivRes[i]:=(DivRes[i]*i+j) mod (i-1);
end;
if Eoln(InPut) then Readln;
j:=-1;
for i:=MinDR to 62 do
if DivRes[i]=0 then begin
j:=i;
Break;
end;
if j=-1 then Writeln('such number is impossible!')
else Writeln(j);
end;
end.