Pagini recente » Cod sursa (job #1753890) | Cod sursa (job #642672) | Cod sursa (job #711249) | Cod sursa (job #2180633) | Cod sursa (job #3175)
Cod sursa(job #3175)
program cifra;
var a,b,i,s:integer;
f,g:text;
y,z:char;
yy,zz:byte;
function gasire(b:integer):byte;
var aux: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;
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
read(f,y,z);
while not eoln(f) do begin
y:=z;
read(f,z);
end;
yy:=ord(y)-48;
zz:=ord(z)-48;
b:=yy*10+zz;
if b>50 then
b:=b-50;
readln(f);
s:=(ultima(b)+5) mod 10;;
writeln(g,s);
inc(i);
end;
close(f);close(g);
end.