Cod sursa(job #2511412)

Utilizator DavidLDavid Lauran DavidL Data 18 decembrie 2019 21:55:23
Problema Suma si numarul divizorilor Scor 70
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.27 kb
#include <vector>
#include <fstream>
using namespace std;
ifstream fi("ssnd.in");
ofstream fo("ssnd.out");

const int MOD = 9973;

int t;
long long n;
bool ciur[1000005];
vector <int> prime;

void faCiur() {
    for (int i = 2; i * i < 1000005; i++)
        if (!ciur[i])
            for (int j = i * i; j < 1000005; j += i)
                ciur[j] = 1;
}

void getPrime() {
    for (int i = 2; i < 1000005; i++)
        if (ciur[i] == 0)
            prime.push_back(i);
}

int main()
{
    faCiur();
    getPrime();

    fi >> t;
    while (t--) {
        fi >> n;
        int cnt = 1;
        long long suma = 1;
        for (auto x: prime) {
            long long e = 0, p = 1;
            while (n % x == 0) {
                e++;
                p = p * x;
                n /= x;
            }
            cnt = cnt * (e + 1);
            suma = suma * (p * x - 1) / (x - 1);

            if (1LL * x * x > n)
                break;
        }
        if (n > 1) { /// mai are un divizor prim (=n)
            cnt = (cnt << 1);
            suma = suma * (1LL * n * n - 1) / (n - 1);
        }
        if (suma == 1 && n > 1) // prim
            suma = n + 1, cnt = 2;
        fo << cnt << " " << suma % MOD << "\n";
    }
    return 0;
}