Cod sursa(job #1646205)

Utilizator theodor1289Theodor Amariucai theodor1289 Data 10 martie 2016 15:25:18
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n, k;
long long a, b;

int main()
{
    fin>>n>>k;
    a=n;
    b=1;

    while(k)
    {
        if(k%2==0)
        {
            a=(a*a)%MOD;
            k/=2;
        }
        else
        {
            b=(b*n)%MOD;
            k--;
        }
    }

    fout<<(a*b/n)%MOD;
    return 0;
}