Cod sursa(job #798987)

Utilizator icb_mnStf Cic icb_mn Data 17 octombrie 2012 18:28:11
Problema Suma si numarul divizorilor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.22 kb
#include<fstream>
#define LL long long
#define M 9973
using namespace std;

LL n, d[50], p[50];
int t, k;

inline void descompune(LL n, LL d[], LL p[], int &k)
{
    LL x = 2;
    k = 0;

    while(n > 1)
    {
        if(!(n % x))
        {
            k++;
            p[k] = x;
            d[k] = 0;
            while(!(n % x))
            {
                d[k]++;
                n /= x;
            }
        }
        x++;
    }
}
int main()
{
    ifstream f("ssnd.in");
    ofstream g("ssnd.out");

    f>>t;

    for(int r = 1; r <= t; ++r)
    {
        f>>n;
        LL nr;
        LL sum;

        descompune(n, d, p, k);

        nr = 1;
        sum = 1;
        LL putere;
        if(k == 1)nr = 2, sum = n + 1;
        else
        {
            for(int i = 1; i <= k; ++i)
            {
                nr = (nr + (1 + d[i])) % M;
                putere =1;
                for(int j = 1; j <= d[i] + 1; ++j)
                    putere =(putere * p[i]) % M;
                putere--;
                putere = (putere/(p[i] - 1))%M;
                sum = (sum * putere) % M;
            }
        }
        g<<nr<<' '<<sum <<'\n';
    }

    g.close();

    return 0;
}