Cod sursa(job #1526031)
| Utilizator | Data | 15 noiembrie 2015 20:34:20 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.6 kb |
#include <iostream>
#include <fstream>
using namespace std;
const int oo = 1999999973 ;
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
int n,m ;
scanf("%d %d",&n ,&m);
unsigned long long x = n ,y = 1;
if (n == 0) printf("1");
while (m > 1) {
if (m%2 == 0) {
x = (x*x) % oo ;
m = m / 2;
}
else {
y = (y*x)%oo;
x = (x*x)%oo;
m = (m-1)/2;
}
}
int result = (x*y) % oo ;
printf("%d" , result);
fclose(stdin);
fclose(stdout);
return 0;
}
