Cod sursa(job #1163790)

Utilizator EhtRalpmetFMI Ardei Claudiu-Alexandru EhtRalpmet Data 1 aprilie 2014 17:04:31
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include<fstream>

using namespace std;
ifstream cin("lgput.in");
ofstream cout("lgput.out");

unsigned long long n,p;

unsigned long long exp(unsigned long long n,unsigned long long p){
    if(p==0){
        return 1;
    }else{
        if(p==1){
            return n%1999999973;
        }else{
            if(p%2){
                return (n%1999999973)*exp(n%1999999973*n%1999999973,p/2)%1999999973;
            }else{
                return exp(n%1999999973*n%1999999973,p/2)%1999999973;
            }
        }
    }
}

int main() {
    cin>>n>>p;
    cout<<exp(n%1999999973,p);



    return 0;
}