Cod sursa(job #2076672)
| Utilizator | Data | 26 noiembrie 2017 22:04:08 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
#define mod 1999999973
typedef long long ll;
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
ll exponentiere(ll x, ll n)
{
if(n==0) return 1;
else if(n==1) return x % mod;
if(n%2==0) exponentiere(x * x % mod, n / 2 % mod);
else if(n%2==1) exponentiere(x * x % mod, (n - 1) / 2 % mod);
}
int main()
{
ll baza, exponent;
in >> baza >> exponent;
out << exponentiere(baza, exponent) % mod;
return 0;
}
