Pagini recente » Cod sursa (job #2588774) | Cod sursa (job #3000405) | Cod sursa (job #679285) | Cod sursa (job #1134623) | Cod sursa (job #3173)
Cod sursa(job #3173)
program cifra;
var a,b,i,s:integer;
f,g:text;
y,z:char;
yy,zz:byte;
function gasire(b:integer):byte;
var n,aux,c:integer;
ok:boolean;
begin
ok:=true;
case b mod 10 of
0: begin gasire:=0;ok:=false;end;
1: begin gasire:=1;ok:=false;end;
5: begin gasire:=5;ok:=false;end;
6: begin gasire:=6;ok:=false;end;
end;
if ok then begin
aux:=b;
for i:=1 to b-1 do begin
b:=b*aux;
b:=b mod 10;
end;
gasire:=b;
{c:=0;
aux:=b;
repeat
INC(C);
b:=b*aux;
b:=b mod 10;
v[c]:=b;
until aux=(c-1);
gasire:=b;}
end;
end;
function ultima(b:integer):byte;
var j:integer;
begin
s:=0;
for j:=1 to b do
s:=s+gasire(j);
s:=s mod 10;
ultima:=s;
end;
begin
assign(f,'cifra.in');reset(f);
assign(g,'cifra.out');rewrite(g);
readln(f,a);
i:=1;
while i<=a do begin
while not eoln(f) do begin
read(f,y);
read(f,z);
end;
if z=#26 then
b:=ord(y)-48
else begin
yy:=ord(y)-48;
zz:=ord(z)-48;
b:=yy*10+zz;
end;
readln(f);
s:=ultima(b);
writeln(g,s);
inc(i);
end;
close(f);close(g);
end.