Cod sursa(job #1537973)
| Utilizator | Data | 28 noiembrie 2015 12:40:58 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int lg_pow(int a, int b){
if(b == 0) return 1;
if(b == 1) return a % 1999999973;
int aux = lg_pow(a, b / 2);
if(b % 2 == 0){
return (1LL*aux * aux) % 1999999973;
} else return (1LL*a * (1LL*aux * aux) % 1999999973) % 1999999973;
}
int main()
{
int a, b;
fin >> a >> b;
fout << lg_pow(a, b);
return 0;
}
