Cod sursa(job #3277033)

Utilizator andrei_botorogeanuBotorogeanu Andrei andrei_botorogeanu Data 15 februarie 2025 11:29:00
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator py Status done
Runda Arhiva educationala Marime 0.46 kb
def const():
    return 1999999973

def power(base,exp):

    ans = 1

    while exp:

       if exp & 1:
          ans = (ans * base ) % const()
       base = (base * base ) % const()
       exp >>=1

    return ans % const()

def solve():
    fin = open("lgput.in","r")
    fout = open("lgput.out","w")
    data = fin.readline().strip().split(" ")
    data = [int(x) for x in data]
    base = data[0]
    exp = data[1]
    fout.write(str(power(base,exp)))

solve()