Cod sursa(job #1040827)

Utilizator tzipleatudTudor Tiplea tzipleatud Data 24 noiembrie 2013 22:58:55
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <fstream>
#include <bitset>
#define MM 6000010

using namespace std;

ifstream f("dtcsu.in");
ofstream g("dtcsu.out");

bitset<MM> V;
int NR=276997, Q, i, j;
long long X;
int ANS;
long long Primes[20]={666013, MM, 3571, 3091, 1046527, 25561, 319993, 999331, 3010349};
long long Plus[20]= {1000000, 0, 3000000, 400000, 2000000, 3123435, 5043132, 4325112, 1003234};

void Add ()
{
    for (j=0; j<9; j++)
        V[X%Primes[j]+Plus[j]]=1;
}

bool Query ()
{
    for (j=0; j<9; j++)
        if (!V[X%Primes[j]+Plus[j]])
            return 0;
    return 1;
}

int main ()
{
    for (i=1; i<=NR; i++)
    {
        f >> X;
        Add();
    }

    f >> Q;
    for (i=1; i<=Q; i++)
    {
        f >> X;
        ANS+=Query();
    }

    g << ANS << '\n';

    f.close();
    g.close();

    return 0;
}