Cod sursa(job #1417572)

Utilizator mihai.constantinConstantin Mihai mihai.constantin Data 10 aprilie 2015 16:35:43
Problema Suma si numarul divizorilor Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 1.35 kb
#include <iostream>
#include <cstdio>
#include <cmath>
#define MOD 9973
#define dmax 1000000
using namespace std;

bool ciur[dmax+5]; int T; long long N,N_1;

void CIUR()
{
    ciur[0]=1; ciur[1]=1;

    for(int i=2; i<=sqrt(dmax); i++)
    {
        if(ciur[i]==0)
        {
            for(int j=2; j*i<=dmax; j++) ciur[i*j]=1;
        }
    }
}

long long Exp_log(long long x, long long y) //CALCULAM x^y PRIN RIDICARE LA PUTERE IN TIMP LOGARITMIC
{
    long long answer=1;

    while(y)
    {
        if(y&1) answer=answer*x;
        x=x*x;
        y >>= 1;
    }

    return answer;
}

int main()
{
    freopen("ssnd.in", "r", stdin);
    freopen("ssnd.out", "w", stdout);

    int i,k,e; bool GASIT; long long Nd,Sd;

    CIUR();

    scanf("%d",&T);

    for(i=1; i<=T; i++)
    {
        scanf("%lld",&N); Nd=1; Sd=1;
        N_1=N;

        for(k=2; k<=dmax; k++)
        {
            if(ciur[k]==0) //k e prim
            {
                e=0; GASIT=0;
                while(N_1%k==0) {N_1=N_1/k; e++; GASIT=1;}

                if(GASIT)
                {
                    Nd=Nd*(e+1);
                    Sd=Sd*((Exp_log(k,e+1)-1)/(k-1)); Sd=Sd%MOD;
                }

                if(N_1==0) break;
            }
        }

        printf("%lld %lld\n",Nd,Sd);

    }


    return 0;
}