Cod sursa(job #2283067)

Utilizator Code_SniperNetoiu Mihail Code_Sniper Data 14 noiembrie 2018 22:11:58
Problema Cifra Scor 0
Compilator py Status done
Runda Arhiva de probleme Marime 0.74 kb
#returneaza ultima cifra a lui x ^ x

def ultCifra(x):
    cif = []
    c = (x * x) % 10
    i = 1
    l = 0
    if x == 1:
        cif.append(1)
        l += 1
    while i < x and c not in cif:                
        cif.append(c)
        i += 1
        l += 1
        c = (c * x) % 10  
    
    if l > 1:
        return cif[(x % l) - 2]
    return cif[0]


def suma(N):
    N=int(N)    
    sf = 0    
    
    i = 1    
    while i <= N:    
        sf = (sf + ultCifra(i)) % 10
        i += 1  
    
    return sf


fn="cifra.in"
with open(fn) as f:
    t=int(f.readline())
    with open("cifra.out","w") as f1:
        for i in range(t):
            k=f.readline()
            f1.write(str(suma(k))+'\n')