Cod sursa(job #1268315)
Utilizator | Data | 20 noiembrie 2014 20:24:26 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include<fstream>
using namespace std;
int a, b;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int putere(int a, int b){
if(b == 0){
return 1;
}
else{
int x = putere(a, b / 2);
if(b % 2 == 0){
return (long long) x * x % 1999999973;
}
else{
return (long long) x * x % 1999999973 * a % 1999999973;
}
}
}
int main(){
fin>> a >> b;
fout<< putere(a, b);
return 0;
}