Cod sursa(job #1187977)
| Utilizator | Data | 18 mai 2014 18:18:07 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int mod = 1999999973;
long long x, n;
long long calculate(long long x, long long n)
{
long long result;
if(n == 1)return x;
if(n%2 == 1) //Impar
return x * calculate(x,n-1) % mod;
result = calculate(x,n/2) % mod;
return result * result % mod;
}
int main()
{
fin >> x >> n;
fout << calculate(x, n);
return 0;
}
