Cod sursa(job #2353847)
Utilizator | Data | 24 februarie 2019 17:30:18 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | py | Status | done |
Runda | Arhiva educationala | Marime | 0.29 kb |
def put(n,p,rest):
if p>1:
if p%2==0:
return put(n*n,p//2,rest)
else:
return put(n*n,p//2,rest*n)
else:
return n*rest
with open("lgput.in","r") as f, open("lgput.out","w") as g:
line=f.read()
n=int(line.split()[0])
p=int(line.split()[1])
g.write(str(put(n,p,1)))