Cod sursa(job #2028966)
| Utilizator | Data | 28 septembrie 2017 21:22:08 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <stdio.h>
#include <vector>
#define NMAX 8
using namespace std;
long long n, p;
const long long div = 1999999973;
int ridicarea() {
if (p == 0)
return 1;
int y = 1;
while (p > 1) {
if (p % 2 == 0) {
n = (n * n) % ;
p = p / 2;
} else {
y *= n;
n *= n;
p = (p - 1) / 2;
}
}
return n * y;
}
int main(int argc, char const *argv[])
{
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%d %d\n", &n, &p);
int n_p = ridicarea(n, p);
printf("%lld\n", n_p % div);
return 0;
}