Pagini recente » Cod sursa (job #374320) | Cod sursa (job #2344702) | Cod sursa (job #2965838) | Cod sursa (job #1828733) | Cod sursa (job #973615)
Cod sursa(job #973615)
#include<stdio.h>
#include<math.h>
FILE *Fin=fopen("lgput.in","r"), *Fout=fopen("lgput.out","w");
int x,y,p=1999999973;
long long a;
long long exp(int x, int n)
{
if(n<0)
return exp(1/x,-n);
else
if(n==0)
return 1;
else
if(n==1)
return x;
else
if(n%2==0)
return exp(x*x,n/2);
else
return x*exp(x*x,(n-1)/2);
}
/*
int main ()
{
fscanf(Fin,"%d",&x);
fscanf(Fin,"%d",&p);
if(p%2==1 && p>2)
a=x*(long long)pow(x*x,(p-1)/2);
else
if(p!=0)
a=(long long)pow((x*x),(p/2));
if(x<y)
fprintf(Fout,"%lld",a);
//printf("%lld",a);
else
fprintf(Fout,"%lld",a%y);
fclose(Fin);
fclose(Fout);
return 0;
}
*/
int main(){
fscanf(Fin,"%d%d",&x,&y);
a = exp(x,y);
fprintf(Fout,"%lld",a%p);
return 0;
}