Cod sursa(job #1507783)

Utilizator doroftei1999Doroftei Andrei doroftei1999 Data 21 octombrie 2015 21:39:07
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include<bits/stdc++.h>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
const long long N=1999999973;
long long n, p;
long long pow(long long a, long long b)
{
    long long rez = 1;
    while(b){
        if (b % 2 == 1){
            rez = (rez * a) % N;
            b--;
        }
        a = (a * a) % N;
        b /= 2;
    }
    return rez;
}
int main ()
{
    f >> n >> p;
    g << pow(n,p);
}