Cod sursa(job #2497895)

Utilizator NeacsuMihaiNeacsu Mihai NeacsuMihai Data 23 noiembrie 2019 11:59:45
Problema Suma si numarul divizorilor Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.01 kb
#include <iostream>
#include <fstream>

using namespace std;

bool pr[1000001];

int putere (int x, int e)
{
    if(e==0) return 1;
    else
    {
        if(e%2==0) return putere(x*x, e/2);
        else return x * putere(x*x, e/2);
    }
}

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


    short n;
    int i, z, p, e;
    long long x, nrdiv, suma;
    bool ok;


    fin>>n;

    for(i=1; i<=n; i++)
    {
        //cout<<"i= "<<i<<"\n";

        fin>>x;

        nrdiv=1;
        suma=1;

        p=2;
        ok=0;

        while(x!=1 && p<=1000000)
        {


            if(x%p==0) ok=1;

            e=0;
            while(x%p==0)
            {
                x=x/p;
                e++;
            }

            nrdiv=nrdiv*(e+1);
            suma=suma * (putere(p, e+1)-1) / (p-1);

            p++;
        }

        if(ok==0) fout<<2<<' '<<(x+1)%9973<<"\n";
        else fout<<nrdiv<<' '<<suma%9973<<"\n";


    }



}