Cod sursa(job #2240478)

Utilizator paul_danutDandelion paul_danut Data 13 septembrie 2018 16:18:35
Problema Suma si numarul divizorilor Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.69 kb
#include <fstream>
#include <math.h>
#include <iostream>

std::ifstream f("ssnd.in");
std::ofstream g("ssnd.out");

using namespace std;

void bruteForce(unsigned long long x, unsigned long long &nr, unsigned long long &sum)
{
    for(auto i=1ULL; i <=x/2; ++i)
    {
        if(x%i == 0)
        {
            ++nr;
            sum += i;
        }
    }

    sum += (sum == 0UL) ? x + 1 : x;
}

int main()
{
    auto t=0U;
    auto x = 0ULL;
    auto sum = 0ULL;
    auto nr = 1ULL;

    f>>t;
    while(t > 0)
    {
        f >> x;
        sum = 0ULL;
        nr = 1ULL;

        bruteForce(x, nr, sum);
        g << nr << ' ' << sum <<'\n';

        --t;
    }
}