Cod sursa(job #1129240)

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

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

int pow(int a, int b){

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

int main(){

    int x,y;
    
    in >> x >> y;
    
    out << pow(x, y);
    
    return 0;
}