Cod sursa(job #2075529)

Utilizator iDanyelArvat Ovidiu Daniel iDanyel Data 25 noiembrie 2017 15:17:20
Problema Sum Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream fin("sum.in");
ofstream fout("sum.out");

void descompunere(int nr, int v[])
{
    int f=2;

    while(nr>1)
    {
        int d=0;

        while(nr%f==0)
        {
            d++;
            nr/=f;
        }

        if(d)
            v[++v[0]]=f;

        f++;

        if(f*f>nr)
            f=nr;
    }
}

int main()
{
    int n, x;
    fin >> n;

    for(int i=1;i<=n;i++)
    {
        fin >> x;

        int multipli[200010]{0}, v[50]{0}, xx=x;
        unsigned long long sum=0;

        descompunere(xx,v);

        for(int j=1;j<=v[0];j++)
            for(int h=v[j];h<=2*x;h+=v[j])
                multipli[h]=1;

        for(int h=1;h<=2*x;h++)
            if(!multipli[h])
                sum+=h;

        fout << sum << "\n";
    }

    return 0;
}