Cod sursa(job #2022094)

Utilizator shantih1Alex S Hill shantih1 Data 15 septembrie 2017 17:01:38
Problema Sum Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <iostream>
#include <fstream>
#define max 1000005

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

long long n, x, y, i, j, tot, d, rez, sum[max];
int nr[max];
bool eth[max];

int main () {
    
    for (i = 2; i <= max; i++)
        if (eth[i] == 0)
        {
            x = i;
            for (j = 2; i * j <= max; j++)
            {
                eth[i*j] = 1;   sum[i*j] += x;  nr[i*j] += ((i*j)-i) / i;
                x += i*j;
            }
        }
    
    fin >> n;
    for (i = 1; i <= n; i++)
    {
        fin >> y;
        tot = (y*2) * (y*2-1) / 2;
        d = 2 * sum[y] + nr[y] * y + y;
        rez = tot - d;
        fout << rez << "\n";
    }
}