Cod sursa(job #1128741)

Utilizator mantisVraciu Stefan mantis Data 27 februarie 2014 18:29:55
Problema Suma divizorilor Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include<fstream>
#define MOD 9901
#define LL long long
using namespace std;
ifstream f("sumdiv.in");
ofstream g("sumdiv.out");
LL a,b,k,d;
LL e[50],p[50];
LL calc(LL a,LL k)
{
	LL p=a;
	while(--k)
		p*=a;
	return p;
}
int main()
{
	f>>a>>b;
	if(!a)
	{
		g<<"0\n";
		g.close();
		return 0;
	}
	if(a==1||!b)
	{
		g<<"1\n";
		g.close();
		return 0;
	}
	d=2;
	while(d*d<=a)
	{
		if(a%d==0)
		{
			e[++k]=0;
			p[k]=d;
			while(a%d==0)
			{
				e[k]++;
				a/=d;
			}
		}
		d++;
	}
	if(a>1)
	{
		e[++k]=1;
		p[k]=a;
	}
	int s=1;
	for(int i=1;i<=k;i++)
		s=(s*calc(p[i],e[i]*b+1)-1)/(p[i]-1)%MOD;
	g<<s<<'\n';
	g.close();
	return 0;
}