Cod sursa(job #2745700)

Utilizator mafiotxrobeert mafiotx Data 26 aprilie 2021 21:57:42
Problema Suma si numarul divizorilor Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.95 kb
#include <iostream> 
#include <fstream>
#include <iomanip>
#include <cmath>
#include <algorithm> 
#include <cstring>

using namespace std;

string NumeFisier = "ssnd";

ifstream fin(NumeFisier + ".in");
ofstream fout(NumeFisier + ".out");

typedef unsigned long long int ull;

const int lenCiur = 1000000;
bool ciur[lenCiur + 1];

void CIUR()
{
	for (int i = 2; i <= lenCiur; i++)
		ciur[i] = 1;

	for (int i = 2; i * i <= lenCiur; i++)
		if (ciur[i])
			for (int j = i * i; j <= lenCiur; j += i)
				ciur[j] = 0;
}


int nrPrime[lenCiur / 10], lenNrPrime;

void NRPRIME()
{
	lenNrPrime = 1;
	nrPrime[1] = 2;

	for (int i = 3; i <= lenCiur; i += 2)
		if (ciur[i])
			nrPrime[++lenNrPrime] = i;
}


long long fastexpo(long long baza, long long exp)
{
	long long rez = 1LL;
	while (exp)
	{
		if (exp % 2LL == 1LL)
			rez *= baza;
		baza *= baza;
		exp >>= 1LL;
	}
	return rez;
}

int NRDIV(long long numar)
{
	int nrDiv = 1;
	int exp = 0;
	long long i = 2;
	while (numar % i == 0)
	{
		exp++;
		numar /= i;
	}
	nrDiv *= (exp + 1);

	for (i = 3; i * i <= numar; i += 2LL)
	{
		int exp = 0;
		while (numar % i == 0)
		{
			exp++;
			numar /= i;
		}
		nrDiv *= exp + 1;
	}
	if (numar > 1)
		nrDiv *= 2;
	return nrDiv;
}


long long SUMADIV(long long numar)
{
	long long suma = 1;
	long long i = 2;
	int exp = 0;
	while (numar % i == 0)
	{
		numar /= i;
		exp++;
	}
	suma = (fastexpo(i, exp + 1LL) - 1LL) / (i - 1LL);

	for (i = 3; i * i <= numar; i += 2LL)
	{
		exp = 0;
		while (numar % i == 0)
		{
			numar /= i;
			exp++;
		}
		if (exp)
			suma *= (fastexpo(i, exp + 1LL) - 1LL) / (i - 1LL);
	}
	if (numar > 1)
		suma *= (fastexpo(numar, 2LL) - 1LL) / (numar - 1LL);
	return suma;
}


int main()
{
	int n;
	long long var;
	fin >> n;
	CIUR();
	NRPRIME();
	for (int i = 1; i <= n; i++)
	{
		fin >> var;
		fout << NRDIV(var) % 9973 << " " << SUMADIV(var) % 9973 << '\n';
	}

}