Cod sursa(job #1354257)
| Utilizator | Data | 21 februarie 2015 18:44:07 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <stdio.h>
using namespace std;
int putere(int a, int b){
if(b==0) return 1;
if(b==1) return a;
else{
if(b%2==0) return (long long)putere(a,b/2)*putere(a,b/2)%1999999973;
else return a*(long long)putere(a,b/2)*putere(a,b/2)%1999999973;
}
}
int main()
{
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
int a,b;
scanf("%d %d", &a, &b);
printf("%d",putere(a,b));
return 0;
}
