Cod sursa(job #2153082)

Utilizator Alex_BubBuburuzan Alexandru Alex_Bub Data 5 martie 2018 22:35:53
Problema Suma si numarul divizorilor Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.39 kb
#include <fstream>
#define ull unsigned long long

using namespace std;

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

int const MOD=9973 , nmax=1000010;
bool ci[nmax];
int v[nmax],nrd;
ull s;

ull mod(ull m)
{
    return (m * m);
}

ull pow(ull base, ull exponent)
{
    if(!exponent) return 1;
    if(exponent == 1) return base;
    return (!(exponent & 1)) ? mod(pow(base, exponent / 2)) : (base * mod(pow(base, exponent / 2)));
}

void ciur()
{
    int z = 1,i;
    v[0] = 2;
    for(i= 3; i * i < nmax; i += 2)
    {
        if(!ci[i])
        {
            v[z++] = i;
            for(int d = i * i ;d < nmax ;d += 2 * i)
                ci[d] = true;
        }
    }
    for(i;i<nmax;i+=2)
    {
        if(!ci[i])
            v[z++]=i;
    }
}

void ssnd(ull x)
{
    s=1; nrd=1;
    for(int i=0; x>1 && 1LL * v[i] * v[i] <= x; i++)
    {
        if(x%v[i]) continue;

        ull p=0;

        while(!(x % v[i]))
        {
            p++;
            x /= v[i];
        }
        nrd *= p + 1;
        s *= ((pow(v[i], p) * v[i] - 1) / (v[i] - 1)) % MOD;
    }

    if(x > 1) {
        nrd *= 2;
        s *= (x + 1) % MOD;
    }

    fout << nrd<<" "<< s % MOD <<'\n';
}

int main()
{
    ciur();
    ull x;
    int n;

    fin >> n;

    while(n--)
    {
        fin >> x;
        ssnd(x);
    }

    return 0;
}