Cod sursa(job #1997132)

Utilizator JustGingaGinga Tudor-Adrian JustGinga Data 3 iulie 2017 14:49:11
Problema Suma si numarul divizorilor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.17 kb
#include <fstream>
#include <cmath>
using namespace std;
ifstream in ("ssnd.in");
ofstream out ("ssnd.out");
const int N = 1000000/2 + 1;
int t, nrDiv = 1; long long n, sDiv = 1;
bool p[N + 1]; int P[N + 1];
int main()
{
    for (int i = 1; i < N/2; i++)
        if (p[i] == 0)
            for (int j = 3*i + 1; j < N/2; j += 2*i + 1)
                p[j] = 1;

    int nr = 0; P[++nr] = 1; P[++nr] = 2;
    for (int i = 1; i < N; i++)
        if (!p[i])
            P[++nr] = 2*i + 1;

    in >> t;
    for (int i = 1; i <= t; i++)
    {
        in >> n;
        if (n & 1 == 0 or (n & 1) and p[(n-1) / 2] == 0) out << 2 << " " << 1 + n << '\n';
        else
        {
            for (int j = 2; P[j] < n/2; j++)
                if (n % P[j] == 0)
                {
                    int exp = 0;
                    for (long long aux = n; aux % P[j] == 0; aux /= P[j]) exp++;
                    nrDiv *= (exp + 1);
                    sDiv *= (pow(P[j], exp+1) - 1) / (P[j] - 1);
                    sDiv %= 9901;
                }
            out << nrDiv << " " << sDiv << '\n';
        }
        nrDiv = sDiv = 1;
    }
    out.close(); return 0;
}