Cod sursa(job #1941244)

Utilizator nartorrewrew narto Data 27 martie 2017 08:48:45
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include <cstdio>

using namespace std;

const long long MOD = 1999999973;
long long n, m;
void citire()
{
    scanf("%lld %lld", &n, &m);
}

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;
        }
        else
        {
            return (x * (putere(x * x % MOD, y / 2) % MOD)) % MOD;
        }
    }
}

int main()
{
    freopen("lgput.in", "r", stdin);
    freopen("lgput.out", "w", stdout);

    citire();
    printf("%lld", putere(n, m));
}