Cod sursa(job #1417503)

Utilizator mihai.constantinConstantin Mihai mihai.constantin Data 10 aprilie 2015 14:47:22
Problema Suma si numarul divizorilor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.31 kb
#include <iostream>
#include <cstdio>
#include <cmath>
#define dmax 1000000
using namespace std;

bool ciur[dmax]; 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; long long Nd,Sd;

    CIUR();

    scanf("%d",&T);

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

        if(ciur[N]==0)
        { Nd=2; Sd=1+N; }
        else
        {
            for(k=2; k<=sqrt(N); k++)
            {
                if(ciur[k]==0) //k e prim
                {
                    e=0;
                    while(N_1%k==0) {N_1=N_1/k; e++;}

                    Nd=Nd*(e+1);

                    Sd=Sd*((Exp_log(k,e+1)-1)/(k-1));
                }
            }

        }

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

    }

    return 0;
}