Cod sursa(job #1156937)
| Utilizator | Data | 28 martie 2014 09:46:51 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include<fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long a, b, p;
long long putere(long long a, long long n){
long long x;
if (n == 1)
return a;
if (n % 2 == 1)
return a * putere(a, n - 1) % 1999999973;
x = putere(a, n / 2) % 1999999973;
return x * x % 1999999973;
}
int main(){
fin >> a >> b;
fout << putere(a, b);
fin.close();
fout.close();
}
