Cod sursa(job #530226)

Utilizator toniobFMI - Barbalau Antonio toniob Data 7 februarie 2011 11:34:34
Problema Suma divizorilor Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <fstream>
using namespace std;

ifstream in ("sumdiv.in");
ofstream out ("sumdiv.out");

const int mod = 9901;
int rez, a, b;

int pow (int a, int n) {
	if (n == 0) {
		return 1;
	}
	if (n % 2) {
		return a * pow (a * a % mod, n >> 1) % mod;
	}
	return pow (a * a % mod, n >> 1) % mod;
}

void add (int x, int y) {
	rez = rez * (pow (x, y + 1) + mod - 1) % mod * pow (x - 1, mod - 2) % mod;
}

void citire () {
	in >> a >> b;
	for (int i = 2; i * i <= a; ++i) {
		if (a % i) {
			int put = 0;
			while (a % i) {
				a /= i;
				++put;
			}
			add (i, put * b);
		}
	}
	if (a != 1) {
		add (a, b);
	}
}

void afisare () {
	out << rez << '\n';
}

int main () {
	citire ();
	
	afisare ();
	
	return 0;
}