Cod sursa(job #1929782)

Utilizator stefdascalescuStefan Dascalescu stefdascalescu Data 18 martie 2017 10:17:15
Problema Sum Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include<bits/stdc++.h>
using namespace std;
ifstream f("sum.in");
ofstream g("sum.out");
long long n,j;
long long x;
int p[40002];
bitset<200002>v;
bitset<200002>np;
int count1=1;
void ciur()
{
    p[count1]=2;
    for(long long i=4;i<=200002;i=i+2)
        np[i]=1;
    for(long long i=3;i<=200002;i+=2)
        if(np[i]==0)
        {
            ++count1;
            p[count1]=i;
            for(j=i+i;j<=200002;j+=i)
                np[j]=1;
        }
}
int main()
{
    f>>n;
    ciur();
    for(int i=1;i<=n;++i)
    {
        f>>x;
        long long x1=x+x;
        long long s=(x+x)*(x+x+1)/2;
        for(int d=1;p[d]<=x1 && x1>1;++d)
            if(x%p[d]==0){
                for(int j=p[d];j<=x1;v[j]=1,j+=p[d])
                    s=s-(1-v[j])*j;
                while(x%p[d]==0)
                    x/=p[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;
}