Cod sursa(job #1915678)

Utilizator ionanghelinaIonut Anghelina ionanghelina Data 8 martie 2017 22:01:47
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include<bits/stdc++.h>
#define dim 100000
using namespace std;
long long n,x,sol,q;
int poz=0;
char buff[dim+5];
unordered_set<long long> hash;
void reduce(long long &x) {
  while(x > 0 and (~x & 1))
    x >>= 1;
}
void read(long long &nr)
{
    nr=0LL;
    while(buff[poz]<'0' || buff[poz]>'9')
    {
        poz++;
        if(poz==dim)
        {
            poz=0;
            fread(buff,1,dim,stdin);
        }
    }
    while(buff[poz]>='0' && buff[poz]<='9')
    {
        nr=nr*10+(buff[poz]-'0');
        poz++;
        if(poz==dim)
        {
            poz=0;
            fread(buff,1,dim,stdin);
        }
    }
}
int main()
{
    freopen("dtcsu.in","r",stdin);
    freopen("dtcsu.out","w",stdout);
    fread(buff,1,dim,stdin);
    for(int i=1;i<=276997;i++)
    {
        read(x);
        reduce(x);
        hash.insert(x);
    }
    read(q);
    for(int i=1;i<=q;i++)
    {
        read(x);
        reduce(x);
        if(hash.find(x)!=hash.end()) sol++;
    }
    printf("%lld\n",sol);
    return 0;
}