Cod sursa(job #3142602)

Utilizator vladm98Munteanu Vlad vladm98 Data 22 iulie 2023 19:09:31
Problema Suma si numarul divizorilor Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.41 kb
#include <bits/stdc++.h>

using namespace std;

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

bool notPrime[1000005];
vector <int> primes;
int MOD = 9973;

void buildPrimes() {
    notPrime[0] = notPrime[1] = true;
    for (int i = 2; i <= 1000000; ++i) {
        if (notPrime[i] == false) {
            primes.push_back(i);
        }
        for (int j = i + i; j <= 1000000; j += i) {
            notPrime[j] = true;
        }
    }
}

// nrDiv = (e1 + 1) * (e2 + 1) * ... * (ep + 1)
// suma = (1 + f1 + f1 ^ 2 + ... + f1 ^ e1) * (1 + f2 + ... + f2 ^ e2) * ...

void computeSumAndCount(long long n) {
    int nrDiv = 1;
    long long suma = 1;
    for (int i = 0; i < primes.size(); ++i) {
        if (1LL * primes[i] * primes[i] > n) break;
        int exponent = 0;
        long long factor = 1;
        long long parantezaSuma = 1;

        while (n % primes[i] == 0) {
            exponent += 1;
            factor *= primes[i];
            parantezaSuma += factor;
            n /= primes[i];
        }

        nrDiv *= (exponent + 1);
        suma *= parantezaSuma;
    }
    if (n > 1) {
        nrDiv *= 2;
        suma *= (1 + n);
    }
    fout << nrDiv % MOD << ' ' << suma % MOD << '\n';
}

int main()
{
    buildPrimes();
    int t;
    fin >> t;
    for (int i = 1; i <= t; ++i) {
        long long n;
        fin >> n;
        computeSumAndCount(n);
    }
}