Cod sursa(job #525842)
| Utilizator | Data | 26 ianuarie 2011 15:41:24 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
#include<cstdio>
using namespace std;
#define REST 1999999973
int n,p;
long long power(int n, int p) {
if (p == 0) return 1;
if (p == 1) return n;
long long x;
x = power(n, p/2);
x = (x * x) % REST;
if (p & 1) return (x*n) % REST;
else return x;
}
int main() {
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%d %d", &n, &p);
printf("%lld\n",power(n,p));
return 0;
}
