Cod sursa(job #1912003)

Utilizator radu.leonardoThe Doctor radu.leonardo Data 7 martie 2017 22:36:09
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include <bits/stdc++.h>
#define MOD 1999999973
using namespace std;
long long x,n;

void pow()
{
    long long y=1;
    if(n<0) x=1/x,n=-n;
    if(n==0) x=1;
    while(n>1)
        if(n%2==0)             x*=x,x%=MOD,n=n/2;
        else       y*=x,y%=MOD,x*=x,x%=MOD,n=n/2;

    x*=y,x%=MOD;
}

void read()
{
    ifstream f("lgput.in");
    f>>x>>n;
    f.close();
}

void write()
{
    ofstream g("lgput.out");
    pow();
    g<<x;
    g.close();
}


int main()
{
    read();
    write();
}