Cod sursa(job #352552)

Utilizator Teodor94Teodor Plop Teodor94 Data 2 octombrie 2009 11:55:08
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.31 kb
#include <cstdio>

const int M=1999999973;
int a,n;

int main()
{
	freopen("lgput.in","r",stdin);
	freopen("lgput.out","w",stdout);
	scanf("%d%d",&a,&n);
	if (n==0) return 1;
	int p=1;
	while (n)
	{
		if (n&1)
			p=(long long)p*a%M;
		a=(long long)a*a%M;
		n>>=1;
	}
	printf("%d",p);
	return 0;
}