Cod sursa(job #1928521)

Utilizator CammieCamelia Lazar Cammie Data 16 martie 2017 14:14:19
Problema Suma si numarul divizorilor Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 1.57 kb
#include <fstream>

#define N 1000002
#define M 9973

using namespace std;

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

int nrdiv, suma, nn, contor, val;
int fr[N], v[100002];

inline void Ciur()
{
    v[0] = 2; nn = 0;
    for (int i = 3; i <= N; i+= 2)
    {
        if (!fr[i])
        {
            v[++nn] = i;
            for (int j = 3; i * j <= N; j += 2)
                fr[i * j] = 1;
        }
    }
}

inline void euclid(int a, int b, long long& x, long long& y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
    }
    else
    {
        long long x0, y0;
        euclid(b, a % b, x0, y0);
        x = y0;
        y = x0 - (a / b) * y0;
    }
}

inline long long inv(int a)
{
    long long invers, inb;
    euclid(a, M, invers, inb);

    if (invers < 0)
        invers += M;
    return invers;
}

inline void Descompune(int nr)
{
    nrdiv = 1;
    contor = 0;
    suma = 1;
    int j = 0;

    while (nr > 1)
    {
        val = 1; contor = 0;
        while (nr % v[j] == 0)
        {
            val *= v[j];
            nr /= v[j];
            contor++;
        }

        nrdiv *= (contor + 1);
        val *= v[j];

        suma *= (val - 1) * inv(v[j] - 1);
        suma %= M;
        j++;
    }
}
inline void Read()
{
    int q, n;

    fin >> q;

    for (int i = 1; i <= q; i++)
    {
        fin >> n;

        Descompune(n);

        fout << nrdiv << " " << suma << "\n";
    }
}

int main ()
{
    Ciur();
    Read();

    fin.close(); fout.close(); return 0;
}