Cod sursa(job #1129246)

Utilizator andreiblaj17Andrei Blaj andreiblaj17 Data 27 februarie 2014 20:57:11
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.49 kb
#include <iostream>
#include <fstream>
#define mod 1999999973
using namespace std;

ifstream in("lgput.in");
ofstream out("lgput.out");

long long pow(long long a, long long b){

    if (b==1) return a%mod;
    else {
        long long h=pow(a, b/2);
        
        if (b%2==0)
            return (h%mod)*(h%mod)%mod;
        else return ((((h%mod)*(h%mod))%mod)*(a%mod))%mod;
    }
    
}

int main(){

    long long x,y;
    
    in >> x >> y;
    
    out << pow(x, y)%mod;
    
    return 0;
}