Cod sursa(job #1612820)

Utilizator andreea_zahariaAndreea Zaharia andreea_zaharia Data 25 februarie 2016 01:36:31
Problema Suma si numarul divizorilor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.51 kb
#include <cstdio>

const long long NMAX = 1000010;
const int MODULO = 9973;

int T;
long long N;
long long NRD, SUMD;

char ciur[NMAX];

void functieCiur () {
    ciur[0] = ciur[1] = 1;
    long long p = 2;
    while (p * p <= NMAX) {
        for (long long i = p * p; i <= N; i += p) {
            ciur[i] = 1;
        }

        while (ciur[++p] == 1);
    }
}

int IM (long long x, int putere = MODULO - 2) {
    if (putere == 1) {
        return x % MODULO;
    }

    if (putere % 2 == 0) {
        return IM ((x * x) % MODULO, putere / 2);
    }
    else {
        return ((x % MODULO) * IM (x, putere - 1)) % MODULO;
    }
}

int main () {
    freopen ("ssnd.in", "r", stdin);
    freopen ("ssnd.out", "w", stdout);

    functieCiur ();

    scanf ("%d", &T);
    while (T--) {
        scanf ("%lld", &N);

        NRD = SUMD = 1;

        for (long long f = 2; ciur[f] * ciur[f] <= N;) {
            long long flap = 1;
            long long p = 0;
            while (N % f == 0) {
                N /= f;
                flap = (flap * f) % MODULO;
                p++;
            }

            if (p >= 1) {
                NRD *= (p + 1);
                SUMD = (SUMD * (((flap * f) - 1) * IM (f - 1))) % MODULO;
            }

            while (ciur[++f] == 1);
        }

        if (N != 1) {
            NRD *= 2;
            SUMD = (SUMD * (((N * N) - 1) * IM (N - 1))) % MODULO;
        }

        printf ("%lld %lld\n", NRD, SUMD);
    }

    return 0;
}