Cod sursa(job #1929779)

Utilizator stefdascalescuStefan Dascalescu stefdascalescu Data 18 martie 2017 10:10:19
Problema Sum Scor 55
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include<bits/stdc++.h>
using namespace std;
ifstream f("sum.in");
ofstream g("sum.out");
int n;
long long x;
bitset<200002>v;
int main()
{
    f>>n;
    for(int i=1;i<=n;++i)
    {
        f>>x;
        long long x1=x+x;
        long long s=(x+x)*(x+x+1)/2;
        int d=2;
        while(d*d<=x)
        {
            if(x%d==0){
                for(int j=d;j<=x1;v[j]=1,j+=d)
                    s=s-(1-v[j])*j;
                while(x%d==0)
                    x/=d;
            }
            ++d;
        }
        if(x!=1)
            for(int j=x;j<=x1;v[j]=1,j+=x)
                    s=s-(1-v[j])*j;
        g<<s<<'\n';
        for(int j=2;j<=x1;++j)
            v[j]=0;
    }
    return 0;
}