Cod sursa(job #1157096)
| Utilizator | Data | 28 martie 2014 11:28:49 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include<fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long a, b, m;
long long putere(long long a, long long b){
int rez;
if (b == 1)
return a % m;
if (b == 2)
return (a * a) % m;
if (b % 2 == 1)
return a * putere(a, b - 1) % m;
else {
rez = putere(a, b / 2);
return rez * rez % m;
}
}
int main(){
m = 1999999973;
fin >> a >> b;
fout << putere(a, b);
}
