Cod sursa(job #1345381)
Utilizator | Data | 17 februarie 2015 16:14:49 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <stdio.h>
using namespace std;
int putere( int x, int p ){
x %= 1999999973;
if ( p == 0 ) return 1;
else if ( p == 1 ) return x;
else if ( p % 2 == 0 ) return putere( x*x, p /2 );
else return putere ( x*x*x, (p-1) / 2 );
}
int main()
{
int a, b;
scanf("%d%d", &a, &b);
printf("%d", putere(a,b));
return 0;
}