Cod sursa(job #1879404)

Utilizator raulstoinStoin Raul raulstoin Data 14 februarie 2017 21:26:38
Problema Suma si numarul divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.28 kb
#include <fstream>
#include <cmath>

#define LMAX 1000005

using namespace std;

int prime[LMAX], L, n;
bool use[LMAX];

void eratothenes()
{
    L = 0;
    prime[L++] = 2;
    for(int i = 3; i < LMAX; i += 2)
        if(!use[i])
        {
            prime[L++] = i;
            for(int j = 3 * i; j < LMAX; j += 2 * i)
                use[j] = 1;
        }
}

int main()
{
    ifstream fin("ssnd.in");
    ofstream fout("ssnd.out");
    long long x;

    eratothenes();

    fin >> n;
    while(n--)
    {
        fin >> x;
        int nr = 1, s = 1, sqrtX = ceil(sqrt(x));

        for(int i = 0; prime[i] <= sqrtX; i++)
            if(x % prime[i] == 0)
            {
                long long aux = x;
                int k = 0;
                while(x % prime[i] == 0)
                {
                    k++;
                    x /= prime[i];
                }
                aux /= x;
                aux *= prime[i];
                aux--;
                s = (s * (aux / (prime[i] - 1))) % 9973;
                nr *= k + 1;
            }
        if(x > 1)
        {
            s = (s * (x + 1)) % 9973;
            nr *= 2;
        }
        fout << nr << " " << s << "\n";
    }

    fin.close();
    fout.close();

    return 0;
}