Cod sursa(job #972753)

Utilizator cosmo0093Raduta Cosmin cosmo0093 Data 12 iulie 2013 16:45:36
Problema Suma si numarul divizorilor Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 1.04 kb
#include <fstream>
#include <cmath>
#include <vector>
#define max 100000

std::vector<int> myV;
void make()
{
	bool bC[max];
	for(int i(0); i < max; i++)
		bC[i] = true;
	for(int i = 2; i <= sqrt(max); i++)
		if(bC[i])
			for(int j = i * i; j < max; j += i)
				bC[j] = false;
	for(int i = 2; i < max; i++)
		if(bC[i]) myV.push_back(i);
}

int main(void)
{
	make();
	std::ofstream out("ssnd.out");
	std::ifstream in("ssnd.in");
	int nV;
	in >> nV;
	long long unsigned nB;
	for(int i = 0; i < nV; i++)
	{
		in >> nB;
		long long unsigned sum(1);
		long long unsigned prod(1);
		long long unsigned cop = nB;
		for(unsigned j(0); j < myV.size(); j++)
		{
			if((long long unsigned)nB % myV[j] != 0) continue;
			int k(1);
			long long unsigned l(myV[j]);
			while((long long unsigned)cop % myV[j] == 0)
			{
				cop /= myV[j];
				l *= myV[j];
				k++;
			}
			sum *= k;
			prod *= (l - 1) / (myV[j] - 1);
		}
		if(sum == 1) sum++;
		if(prod == 1) prod += nB; 
		out << sum << ' ' << prod << "\n";
	}
	return 0;
}