Cod sursa(job #2398973)

Utilizator AndreiStrAndrei Stroici AndreiStr Data 6 aprilie 2019 16:28:23
Problema Suma si numarul divizorilor Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.99 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("ssnd.in");
ofstream g("ssnd.out");
const long long N=1000000000000;
long long s;
long long n,a,x;
long long prim(long long x)
{
    int e=1,rez=1,s=0,y=x;
    for(int d=2; d*d<=x; d++)
        if(x%d==0)
        {
            s+=d;
            s+=x/d;
            e=1;
            while(y%d==0)
            {
                e++;
                y/=d;
            }
            rez*=e;
        }
    if(y>1)
        rez*=2;
    return rez;
}

int main()
{
    f>>n;
    for(int i=1; i<=n; i++)
    {
        s=0;
        f>>x;
        if(x==1)
            g<<"1 1\n";
        else
        {
            s++;
            s+=x;
            g<<prim(x)<<' ';
            for(int d=2; d*d<=x; d++)
                if(x%d==0)
                {
                    s+=d;
                    if(d*d!=x)
                        s+=x/d;
                }
            g<<s<<'\n';
        }
    }
    return 0;
}