Cod sursa(job #689869)
| Utilizator | Data | 24 februarie 2012 22:05:54 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
int putere( int n, int exp ){
if( exp == 0 ) return 1;
if( exp % 2 == 0 ){
int a = putere( n, exp / 2 );
return a*a;
}
else{
int a = putere( n, ( exp - 1 ) / 2 );
return n * a * a;
}
}
int main(){
ifstream in( "lgput.in" );
ofstream out( "lgput.out" );
int n, exp;
in >> n >> exp;
out << putere( n, exp ) % 1999999973;
in.close();
out.close();
return 0;
}
