Cod sursa(job #1489945)
Utilizator | Data | 22 septembrie 2015 14:25:42 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <iostream>
#include <fstream>
#define MOD 1999999973
using namespace std;
int x,n;
int power(int x,int n)
{
if(n==0)
return 1;
if(n%2==0)
return (power((x*x)%MOD,n/2))%MOD;
return (power(x,n-1)*x)%MOD;
}
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%d %d",&x,&n);
printf("%d",power(x,n));
return 0;
}