Cod sursa(job #2735596)

Utilizator Mihai7218Bratu Mihai-Alexandru Mihai7218 Data 2 aprilie 2021 16:45:24
Problema Suma si numarul divizorilor Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.46 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("ssnd.in");
ofstream fout("ssnd.out");
int n, t, ciur[1000001], d, ndiv, sdiv, i, j;
long long expsqr(long long n, long long p)
{
    if (p == 0) return 1;
    else if (p == 1) return n;
    else if (p % 2 == 0) return (expsqr(n*n, p/2));
    else if (p % 2 == 1) return (n*expsqr(n*n, (p-1)/2));
}
int main()
{
    ciur[0] = 1;
    ciur[1] = 1;
    for (i = 2; i*i <= 1000000; i++)
    {
        if (ciur[i] == 0)
            for (j = 2; j <= 1000000/i; j++)
                ciur[i*j] = 1;
    }
    fin >> t;
    queue<pair<int,int>> Q1;
    queue<int> Q2;
    for (i = 1; i <= t; i++)
    {
        fin >> n;
        for (j = 2; j <= n; j++)
        {
            if (ciur[j] == 0)
            {
                d = 0;
                while (n%j == 0)
                {
                    d++;
                    n/=j;
                }
                if (d != 0)
                {
                    Q2.push(d);
                    Q1.push(make_pair(j, d));
                }
            }
        }
        ndiv = 1; sdiv = 1;
        while(!Q2.empty())
        {
            ndiv*=(Q2.front()+1);
            Q2.pop();
        }
        while(!Q1.empty())
        {
            sdiv *= ((expsqr(Q1.front().first, (Q1.front().second+1))-1)/(Q1.front().first-1));
            Q1.pop();
        }
        fout << ndiv << " " << sdiv << "\n";
    }
    return 0;
}