Cod sursa(job #1008744)

Utilizator andreiblaj17Andrei Blaj andreiblaj17 Data 11 octombrie 2013 19:26:15
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.47 kb
#include <iostream>
#include <fstream>
#define modulo 1999999973
#define unint unsigned int

using namespace std;

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

unsigned int n,p;

int putere(unint baza, unint exp){
    if (exp==1) return n;
    else {
        int half=putere(n, int(exp/2));
        
        if (exp % 2 == 0) return half*half;
        else return half*half*baza;
    }
}

int main(){
    in >> n >> p;

    out << putere(n, p) << "\n";
    
    return 0;
}