Cod sursa(job #201648)

Utilizator devilkindSavin Tiberiu devilkind Data 2 august 2008 15:00:58
Problema Suma divizorilor Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.15 kb
#include <stdio.h>
#include <vector>

using namespace std;

#define modulo 9901
#define pb push_back
#define sz size()
#define LL long long

vector<LL> v;
LL a,b,sol;

LL power(LL x, LL e)
{
        LL i,k,ret=1;

        for (k=x%modulo,i=0; (1 << i)<=e;i++)
                {
                        if ( e&(1 << i) ) ret=(ret*k)%modulo;
                        k=(k*k)%modulo;
                }
        return ret;
}

void compute(LL p, LL e)
{
	e=e*b;
//	printf("%lld ",e);

	LL x,y,z;

	x=p%modulo;
	
	y=power(p,e)-1;
	if (y<0) y+=modulo;

	z=power(p-1,9899);
	v.pb( ( ( (x*y)%modulo )*z )%modulo );

//	printf("%lld %lld %lld %lld\n",x,y,z,v[ v.sz -1 ]);
}

void back(LL nivel, LL nr)
{
	if (nivel==v.sz)
	{
		sol=(sol+nr)%modulo;
		return;
	}

	back(nivel+1, nr);
	back(nivel+1, (nr*v[nivel])%modulo );
}

int main()
{
	freopen("sumdiv.in","r",stdin);
	freopen("sumdiv.out","w",stdout);

	LL i,p,e;

	scanf("%lld %lld",&a,&b);

	for (i=2;i*i<=a;i++)
	{
		if (a%i) continue;
		
		p=i;
		for (e=0;a%p==0;e++,a/=p);
//		printf("%lld %lld\n",p,e);
		compute(p,e);
	}
	
	if (a>1) compute(a,1);
//	printf("%lld\n",a);

	back(0,1);
	printf("%lld",sol%modulo);
	return 0;
}