Cod sursa(job #2121467)

Utilizator Alex_BubBuburuzan Alexandru Alex_Bub Data 3 februarie 2018 18:37:22
Problema Suma si numarul divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.26 kb
#include <fstream>
#define ull unsigned long long

using namespace std;

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

int const MOD=9973 , nmax=1000001;
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+=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&&i<nmax;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));
    }
    fout << nrd<<" "<< s % MOD <<'\n';
}

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

    fin >> n;

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

    return 0;
}