Cod sursa(job #1040825)

Utilizator tzipleatudTudor Tiplea tzipleatud Data 24 noiembrie 2013 22:56:31
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 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, X, j;
int ANS;
int Primes[20]={666013, MM, 3571, 3091, 1046527, 25561, 319993, 999331, 3010349};
int 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 ()
{
    bool ans=1;
    for (j=0; j<9; j++)
        ans&=V[X%Primes[j]+Plus[j]];
    return ans;
}

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;
}