Cod sursa(job #1064173)

Utilizator pafcalUAIC-Alexandru-Pavaloi pafcal Data 21 decembrie 2013 17:09:51
Problema Suma divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.17 kb
#include<fstream>
#include<math.h>
using namespace std;
ifstream fin("sumdiv.in");
ofstream fout("sumdiv.out");

struct prim
{
	int valoare, numar;
};
prim V[30];
long a, b, c, x, p, q, j, i, k;
int main()
{
	fin >> a >> b;
	i = 2; k = 1;
	
	c = sqrt(a);
	if (a == 0 ) fout << "0";
	else if (a == 1 || b==0) fout << "1";
	else {
		while (i <= c && a > 1)
		{
			if (a%i == 0)
			{
				V[k].valoare = i;
				while (a%i == 0)
				{

					V[k].numar++;
					a /= i;
				}
				k++;
			}
			i++;
		}
		if (a != 1) { V[k].valoare = a; V[k].numar = 1; }
		else k--;

		p = 1; q = 1;
		for (i = 1; i <= k; i++)
		{
			long aux = 1;
			c = V[i].numar*b + 1;
			x = V[i].valoare;
			for (int j = 0; (1 << j) <= c; ++j)
			{
				if (((1 << j) & c) > 0) aux = (aux*x) % 9901;
				x = (x*x) % 9901;
			}
			q = (q*(V[i].valoare - 1)) % 9901;
			aux = (9901 + aux - 1) % 9901;
			p *= aux;
			p = p % 9901;
		}

		x = q; q = 1;
		for (int j = 0; (1 << j) <= 9899; ++j)
		{
			if (((1 << j) & 9899) > 0) q = (q*x) % 9901; //inversul modular al lui q
			x = (x*x) % 9901;
		}
		q = q % 9901;
		p = (p*q) % 9901;


		fout << p;
	}
	return 0;
}