Cod sursa(job #3326907)

Utilizator zionlyismAdobroaiei David zionlyism Data 1 decembrie 2025 11:07:51
Problema Suma si numarul divizorilor Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.96 kb
#include <fstream>

#define CMAX 1000002

using namespace std;

ifstream fin ("ssnd.in");
ofstream fout ("ssnd.out");

long long int n, t;
bool ciur[CMAX];

void eratostene();
void DIV(long long int n);

int main()
{
    eratostene();
    int i;
    fin>>t;
    for(i = 1; i <= t; i++)
    {
        fin>>n;
        DIV(n);
    }
    return 0;
}

void DIV(long long int n)
{
 int contor = 2, d;
 long long int sumdiv = n + 1;
 //determinare nr divizori
 if(ciur[n] == 0) //n este prim
    fout<<contor<<' '<<sumdiv<<'\n';
    else
    {
     for(d = 2; d * d < n; d++)
        if(n % d == 0)
        {
           contor += 2;
           sumdiv = sumdiv + d + (n / d);
        }
     if(d * d == n) {sumdiv += d; contor++;} //patrat perfect
     fout<<contor<<' '<<sumdiv<<'\n';
    }
}

void eratostene()
{
 int i, j;
 ciur[0] = ciur[1] = 1;
 for(i = 2; i <= CMAX; i++)
    for(j = i + i; j <= CMAX;j += i)
        ciur[j] = 1;
}