Cod sursa(job #1183094)
| Utilizator | Data | 8 mai 2014 15:11:49 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
#include <iostream>
using namespace std;
int n, p;
long long exp(long long x, long long n)
{
if (n == 0)
return 1;
if (n == 1)
return x;
if (n % 2 == 0)
return exp(x * x, n / 2) % 1999999973;
if (n % 2 != 0)
return (x * (exp(x * x, (n - 1) / 2) % 1999999973)) % 1999999973;
}
int main()
{
ifstream cin("lgput.in");
ofstream cout("lgput.out");
cin >> n >> p;
cout << exp(n, p);
return 0;
}
