Cod sursa(job #1806587)

Utilizator calin1Serban Calin calin1 Data 15 noiembrie 2016 15:45:28
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
#include <iostream>
#include <cstdio>
#define modul 1999999973

using namespace std;

long long n, p;

void putere()
{
    long long tmp = 1;

    while(p != 1)
    {

        if(p % 2 == 1)
        {
            tmp = (tmp * n) % modul;
            p--;
        }

        n = (n * n) % modul;
        p /= 2;

    }

    printf("%lld",(n * tmp) % modul);
}

void citire()
{
    scanf("%lld %lld",&n,&p);

    putere();
}

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

    citire();

    return 0;
}