Cod sursa(job #2722230)

Utilizator AndreiBOTOBotocan Andrei AndreiBOTO Data 12 martie 2021 17:54:06
Problema Suma si numarul divizorilor Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.39 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin ("ssnd.in");
ofstream fout ("ssnd.out");
const int NMAX=1005;
int v[NMAX],n;
int lgput(int a,int b)
{
    int total=1;
    if(b==0)
    return 1;
    else
        {
            if(b%2==0)
            {
                total=lgput(a,b/2);
                total=total*total;
                return total;
            }
            else
            {
                total=lgput(a,b/2);
                total=total*total;
                return total*a;
            }
        }
}
int nrd(int n)
{
    int d=2,p=0,total=1,s=1,ex=1;
    while(n>1)
    {
        p=0;
        while(n%d==0)
        {
            n=n/d;
            p++;
        }
        if(p>0)
        {
            total*=(p+1);
        }
        d++;
        if(d*d>n)
            d=n;
    }
    return total;
}
int sdivi(int n)
{
    int d=2,p=0,s=1,ex=1;
    while(n>1)
    {
        p=0;
        while(n%d==0)
        {
            n=n/d;
            p++;
        }
        if(p>0)
        {
        s*=lgput(d,p+1)-1;
            ex*=(d-1);
        }
        d++;
        if(d*d>n)
            d=n;
    }
    return s/ex;
}
int main()
{
    int n,a,b,x,i,m;
    fin>>n;
    for(i=1;i<=n;i++)
    {
        fin>>m;
        fout<<nrd(m)<<" "<<sdivi(m)<<"/n";
    }
    return 0;
}