Cod sursa(job #194105)

Utilizator raduzerRadu Zernoveanu raduzer Data 8 iunie 2008 13:26:38
Problema Suma divizorilor Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <stdio.h>

int n,x,y,i,j,a[100000],b[100000],k;
long long s,s2,z;

int main()
{
	freopen("sumdiv.in","r",stdin);
	freopen("sumdiv.out","w",stdout);
	scanf("%d%d",&x,&y);
	for (i=2; i*i<=x; ++i)
	{
		if (x%i) continue;
		a[++n]=i;
		while (x%i==0) { x/=i; ++b[n]; }
	}
	if (x>1) { a[++n]=x; b[n]=1; }
	s=1;
	for (i=1; i<=n; ++i)
	{
		b[i]*=y;
		long long t=1,q=a[i];   
		for (k=b[i]; k>0; k/=2)   
		{   
			if (k%2==1) t=(t*q)%9901;   
			q=(q*q)%9901;   
		}   
		z=((long long)(t*a[i]-1)/(a[i]-1));
		if (z==0) z=1;
		s=(s*z)%9901;
	}
	printf("%lld\n",s);
	return 0;
}