Cod sursa(job #146509)
Utilizator | Data | 1 martie 2008 20:43:28 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.34 kb |
#include<stdio.h>
#define Mod 1999999973
FILE*f=fopen("lgput.in","r");
FILE*g=fopen("lgput.out","w");
long long a,b,exp=1;
int main()
{
fscanf(f,"%lld %lld",&a,&b);
a=a%Mod;
while(b)
{
if(b%2==1) { exp=((exp%Mod)*(a%Mod))%Mod; b/=2; }
else { a=((a%Mod)*(a%Mod))%Mod; --b;}
}
fprintf(g,"%lld\n",exp);
return 0;
}