Cod sursa(job #350463)

Utilizator TFifesPorcescu Alexandru TFifes Data 23 septembrie 2009 22:57:58
Problema Sum Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include<iostream>
#include<fstream>
using namespace std;
void ciur(unsigned long n,bool v[])
{
    unsigned long i,j;
    for(i=2;i<=n;i++)
    {
    if(v[i]==0)
    {
        for(j=2*i;j<=n;j+=i)
        v[j]=1;
    }
    }
}
int main ()
{
    ifstream a("sum.in");
    ofstream b("sum.out");
    unsigned long long s=0;
    bool v[200000];
    unsigned long n,i,x,max=0,j;
    a>>n;
    for(i=1;i<=n;i++)
    {
        a>>x;
        if(x>max)
        max=x;
    }
    ciur(max*2,v);
    a.seekg(0,ios::beg);
    a>>n;
    for(i=1;i<=n;i++)
    {
      a>>x;
      for(j=2;j<=x;j++)
      {
          if(v[j]==0 || v[x]==0)
          {
              if(v[x]!=v[j])
              {
                  s+=j;
              }
          }
      }
      b<<s<<"\n";
      s=0;
    }
    a.close();
    b.close();
    return 0;
}