Cod sursa(job #1698684)

Utilizator perjulucianPerju Lucian Ionut perjulucian Data 5 mai 2016 00:43:09
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.51 kb
#include <fstream>
#include <iostream>

std::ifstream f("lgput.in");
std::ofstream g("lgput.out");
using big = long long;

const big toDiv = 1999999973;




big pow(big n, big p){
    if(p == 0){
        return 1;
    }
    if(p == 1){
        return n % toDiv;
    }

    if(p % 2 == 0){
        return pow(n * n , p / 2) % toDiv;
    }

    return (n * pow(n * n , p / 2)) % toDiv ;
    
}


int main(){

    big N, P;
    
    f >> N >> P;

    g << pow(N,P);

    

    f.close();
    g.close();
    
    return 0;  
}