Cod sursa(job #933489)

Utilizator NicuCJNicu B. NicuCJ Data 30 martie 2013 00:18:50
Problema Suma divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>
#include <algorithm>
#define mod 9901
using namespace std;

unsigned long long putere(unsigned long long bz, unsigned long long xp)
{
	if(xp==0)
		return 1;
	else if(xp%2) return (((bz%mod*(putere(bz, xp/2)%mod))%mod)*(putere(bz, xp/2)%mod))%mod;
	return (((putere(bz, xp/2))%mod)*(putere(bz, xp/2)%mod))%mod;
}
unsigned long long a, b, aux, phi, i, pr[1000001], ex[1000001];
unsigned long long rez, k;
int main()
{
	ifstream f("sumdiv.in");
	ofstream g("sumdiv.out");
	f>>a>>b;
	phi=mod-1;
	for(i=2; i*i<=a; i++)
	{
		if(a%i==0)
		{
			k++;
			pr[k]=i;
			while(a%i==0)
			{
				ex[k]++;
				a/=i;
			}
		}
	}
	if(a!=1)
	{
		if(!binary_search(pr+1, pr+k+1, a))
		{
			k++;
			pr[k]=a;
			ex[k]++;
		}
		else ex[lower_bound(pr+1, pr+k+1, a)-pr]++;
	}
	rez=1;
	for(i=1; i<=k; i++)
	{
		ex[i]*=b;
		rez=(rez*(((putere(pr[i], ex[i]+1))-1)%mod*(putere(pr[i]-1, phi-1)%mod))%mod)%mod;
	}
	g<<rez;
}