Cod sursa(job #1739388)

Utilizator danyvsDan Castan danyvs Data 9 august 2016 13:28:15
Problema Suma si numarul divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.18 kb
#include <fstream>

using namespace std;

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

const int mod = 9973;

long long Power(long long a, long long b)
{
    long long x, i;
    x = a;
    for (i = 2; i <= b; ++ i)
        a *= x;
    return a;
}

void Solve(long long x)
{
    long long sum, nrdiv, ct, d;
    ct = 0;
    while (x % 2 == 0)
        {
         ++ ct;
         x /= 2;
        }
    nrdiv = ct + 1;
    sum = ((Power(2, ct + 1) - 1) / (2 - 1)) % mod;
    d = 3;
    while (d * d <= x)
        {
         ct = 0;
         while (x % d == 0)
            {
             ++ ct;
             x /= d;
            }
         if (ct)
            {
             nrdiv *= ct + 1;
             sum *= ((Power(d, ct + 1) - 1) / (d - 1)) % mod;
            }
         d += 2;
        }
    if (x != 1)
        {
         nrdiv *= 2;
         sum *= ((Power(x, 2) - 1) / (x - 1)) % mod;
        }
    fout << nrdiv << " " << sum % mod << "\n";
}

int main()
{
    long long n, x, i;
    fin >> n;
    for (i = 1; i <= n; ++ i)
        {
         fin >> x;
         Solve(x);
        }
    fin.close();
    fout.close();
    return 0;
}