Cod sursa(job #1355145)
Utilizator | Data | 22 februarie 2015 14:12:08 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <stdio.h>
#include <math.h>
#define Mod 1999999973
using namespace std;
long long sol = 1,a,p;
int main()
{
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%lld %lld",&a,&p);
for(int i=0; (1<<i)<=p;++i )
{
if( ((1<<i)&p) > 0)
{
sol = (sol * a)%Mod;
}
a = (a * a)%Mod;
}
printf("%lld",sol);
return 0;
}