Cod sursa(job #1183099)
| Utilizator | Data | 8 mai 2014 15:14:35 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <fstream>
#include <iostream>
using namespace std;
long long 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) % 1999999973, 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;
n = n % 1999999973;
cout << exp(n, p);
return 0;
}
