Cod sursa(job #1151504)

Utilizator Barcau_EmanuelBarcau Emanuel Barcau_Emanuel Data 24 martie 2014 10:35:12
Problema Suma si numarul divizorilor Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.96 kb
#include<fstream>
#include<cmath>

using namespace std;
ifstream f("ssnd.in");
ofstream g("ssnd.out");
long long n,m,i,t,j,k,l,o,sdf,nrf,nrprim[78500];
bool a[10000002];

void ciur()
{
    long i,j;
    for(i=2;i<=1000000;i++)
    {
        if(a[i]==0)
        {
            for(j=i+i;j<=1000000;j+=i) a[j]=1;
            nrprim[0]++;
            nrprim[nrprim[0]]=i;
        }
    }
}

void desc(int k)
{
    int i,j,nrk,nrp,nrd;

    nrk=sqrt(k);
    nrf=sdf=1;
    for(i=1;i<=nrprim[0]&&k>1;i++)
    {
        if(k%nrprim[i]==0)
        {
            nrp=nrprim[i];
            nrd=0;
            while(k%nrp==0)
            {
                k=k/nrp;
                nrd++;
            }
            nrf*=(nrd+1);
            sdf*=((pow(nrp,nrd+1)-1)/(nrp-1));
        }
    }
    g<<nrf<<" "<<sdf<<"\n";
}

int main()
{
    f>>t;
    ciur();
    while(t--)
    {
        f>>k;
        desc(k);
    }

    return 0;
}