Cod sursa(job #1408286)

Utilizator VladuZ1338Vlad Vlad VladuZ1338 Data 29 martie 2015 22:43:13
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <cstdio>

using namespace std;

long long x, y, mod=1999999973;

long long putere (long long x, long long y)
{
    if(y==1) return x%mod;
    else if (y%2==0) return putere((x*x)%mod, (y/2)%mod)%mod;
    else return (x*(putere((x*x)%mod, (y/2)%mod))%mod)%mod;
}

int main()
{
    freopen ("lgput.in", "r", stdin);
    freopen ("lgput.out", "w", stdout);
    scanf ("%lld%lld", &x, &y);
    long long sol=putere(x,y);
    printf ("%lld", sol);
}