Cod sursa(job #201647)

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

using namespace std;

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

vector<int> v;
int a,b,sol;
int st[20];

int power(int x, int e)
{
        int 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(int p, int e)
{
	e=e*b;
	
	int x,y,z;

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

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

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

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

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

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

	int i,p,e;

	scanf("%d %d",&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("%d ",p);
		compute(p,e);
	}
	
	if (a>1) compute(a,1);

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