Pagini recente » Cod sursa (job #812738) | Cod sursa (job #1705656) | Cod sursa (job #1620975) | Cod sursa (job #1739262) | Cod sursa (job #487535)
Cod sursa(job #487535)
{
Determinati ultima cifra a sumei:
S = 1^1 + 2^2 + 3^3 + ... + n^n
n<=500
}
program ultimaCifra;
var
pc:integer; {penultima cifra a numarului}
uc:integer; {ultima cifra a numarului}
rez:integer;
f,o:text;
i,t:integer;
function fx(n:integer):integer;
begin
case n of
0: fx:=0;
1: fx:=1;
2: fx:=5 + (((pc mod 2) * 2) mod 2) * 2;
3: fx:=2;
4: fx:=8;
5: fx:=3;
6: fx:=9;
7: fx:=2;
8: fx:=0;
9: fx:=9;
end;
end;
begin
assign(f,'cifra.in');
reset(f);
assign(o,'cifra.out');
rewrite(o);
read(f,t);
for i:=1 to t do begin
readln(f);
pc:=0;
read(f,uc);
while not(eoln(f)) do
begin
pc := uc;
read(f,uc);
end;
rez:=(3 * pc + (pc mod 2) * 2 + fx(uc)) mod 10;
writeln(o, rez);
end;
close(f);
close(o);
end.