Cod sursa(job #1488352)
| Utilizator | Data | 18 septembrie 2015 19:47:31 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.61 kb |
#include <stdio.h>
#define inff 1999999973
using namespace std;
long long x, n;
void read()
{
scanf("%lld %lld", &x, &n);
}
long long solve(long long x, long long n)
{
if(n == 0)
return 1;
if(n == 1)
return x % inff;
if(n % 2 == 0)
return (solve(x * x % inff, n / 2) % inff);
else
return (x * solve(x * x % inff, (n - 1)/2)) % inff;
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
read();
printf("%lld", solve(x, n));
fclose(stdin);
fclose(stdout);
return 0;
}
