Cod sursa(job #2118713)
| Utilizator | Data | 30 ianuarie 2018 21:35:21 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long int b = 1999999973;
long long int power(long long int x, long long int n)
{
x %= b;
if(n < 0) return power(1/x, -n);
else if(n == 0) return 1;
else if(n == 1) return x;
else if(n%2 == 0) return (power(x*x, n/2))%b;
else if(n%2 == 1) return (x * power(x*x, (n-1)/2))%b;
}
int main()
{
long long int n,x;
fin>>x>>n;
x = power(x,n);
fout<<x;
}
