Cod sursa(job #3256483)

Utilizator tomavladnicolae@gmail.comTomavlad [email protected] Data 14 noiembrie 2024 18:03:15
Problema Dtcsu Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <bits/stdc++.h>
#define P 8887 /// P este prim
using namespace std;

ifstream fin("dtcsu.in");
ofstream fout("dtcsu.out");
/**
23 56 14 18 36 40 33
P = 7
h[i] = lista numerelor care dau restul i prin impartire la P
h[0] = 56, 14
h[1] = 36
h[2] = 23
h[3] =
h[4] = 18
h[5] = 40, 33
h[6] =

*/
vector<int> h[P];
int n;

int Cauta(long long x)
{
    int r = x % P;
    for (long long e : h[r])
        if (e == x) return 1;
    return 0;
}

int main()
{
    int i, Q, cnt, r;
    long long x;
    n=276997;
    cnt=0;
    for(i=1;i<=n;i++)
    {
        fin>>x;
        x/=(x&(-x));
        r = x % P;
        if (Cauta(x) == 0)
            h[r].push_back(x);
    }
    fin>>Q;
    while(Q--)
    {
        fin>>x;
        if (x > 0)
        {
            x/=(x&(-x));
            cnt += Cauta(x);
        }
    }
    fout<<cnt<<'\n';
    return 0;
}