Cod sursa(job #2378985)

Utilizator dey44andIoja Andrei-Iosif dey44and Data 12 martie 2019 19:47:41
Problema Suma si numarul divizorilor Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.48 kb
#include <fstream>
#include <vector>

#define input "ssnd.in"
#define output "ssnd.out"
#define ERAS_MAX 1000000
#define MOD 9973

using namespace std;
typedef long long ll;

ifstream in(input);
ofstream out(output);

vector < ll > primes;
int Tests;
bool erastostene[ERAS_MAX + 5];

void Ciur()
{
	primes.push_back(2);
	for (int i = 3; i <= ERAS_MAX; i += 2)
		if (!erastostene[i])
		{
			primes.push_back(i);
			for (int j = 3 * i; j <= ERAS_MAX; j += 2 * i)
				erastostene[j] = 1;
		}
}

ll fast_exp(ll base, ll exp)
{
	if (!exp) return 1;
	if (exp == 1) return base;
	if (exp % 2) return base * fast_exp(base, exp - 1);
	return fast_exp(base * base, exp / 2);
}

void Solve(ll number)
{
	unsigned pivot = 0;
	int p = 0;
	ll nr_div = 1, suma_div = 1;
	while (number != 1)
	{
		if (number % primes[pivot] == 0)
		{
			while (number % primes[pivot] == 0) number /= primes[pivot], p++;
			ll prim = primes[pivot], expo = p;
			//out << prim << " " << expo << " -> ";
			ll numarator = (fast_exp(prim, expo + 1) - 1);
			ll numitor = (prim - 1);
			//out << numarator << " " << numitor << "\n";
			nr_div = (nr_div * (expo + 1)) % MOD;
			suma_div = (suma_div * numarator / numitor) % MOD;
		}
		p = 0, pivot++;
	}
	out << nr_div << " " << suma_div << "\n";
	//out << "\n";
}

void Read_Data()
{
	in >> Tests;
	while (Tests--)
	{
		ll number; in >> number;
		Solve(number);
	}
}


int main()
{
	Ciur();
	Read_Data();
	return 0;
}