Cod sursa(job #1347073)

Utilizator ImGeluGelu Ungur ImGelu Data 18 februarie 2015 19:32:16
Problema Suma si numarul divizorilor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.81 kb
#include <iostream>
#include <fstream>

using namespace std;

int putere(int a, int b){
int p=1;
for(int i=1; i<=b; i++)
    p=p*a;

return p;
}

int nrdivi(int n){
 int nrdiv=1, exp, d=2;
 while(n>1){
    exp=0;
    while(n%d==0){
        n=n/d;
        exp++;

    }
    d++;
    nrdiv=nrdiv*(exp+1);

 }
 return nrdiv;
}

int sdiv(int n){
 int nrdiv=1, exp, d=2, suma=1;
 while(n>1){
    exp=0;
    while(n%d==0){
        n=n/d;
        exp++;

    }
    d++;
    nrdiv=nrdiv*(exp+1);
    if(exp!=0) suma=suma*((putere(d,exp+1)-1)/(d-1));

 }
 return suma;
}

int main()
{
    ifstream fin("snnd.in");
    ofstream fout("snnd.out");
    int t,n;
    fin>>t;
    for(int i=1; i<=t; i++){
        fin>>n;
        fout<<nrdivi(n)<<' '<<sdiv(n)<<"\n";}



    return 0;
}