Pagini recente » Cod sursa (job #2891718) | Cod sursa (job #1303528) | Cod sursa (job #2105532) | Cod sursa (job #1049618) | Cod sursa (job #1336984)
#include <bits/stdc++.h>
using namespace std;
///------------------------------------------------------
const int BS = 1 << 15;
char buffer[BS];
int position = BS;
inline char getChar()
{
if ( position == BS )
{
position = 0;
fread( buffer, BS, 1, stdin );
}
return buffer[ position++ ];
}
inline long long getNr()
{
register long long a = 0;
char ch;
do
{
ch = getChar();
} while ( !isdigit(ch) );
do
{
a = (a << 3) + (a << 1) + ch - '0';
ch = getChar();
} while ( isdigit(ch) );
return a;
}
///------------------------------------------------------
struct BloomFilter
{
static const int NumberOfPrimes = 5;
static const int Primes[NumberOfPrimes];
struct BitSet
{
int N;
unsigned long long *b;
explicit BitSet() : N(0), b(nullptr)
{
}
BitSet(const int _N) : N(_N), b(new unsigned long long[N / 64 + 1])
{
for ( int i = 0; i < N / 64 + 1; ++i )
b[i] = 0;
}
void set(const int pos)
{
b[pos >> 6] |= ( 1ULL << ( pos & 63 ) );
}
bool test(const int pos)
{
return b[pos >> 6] & ( 1ULL << ( pos & 63 ) );
}
};
};
const int Primes[] = { 666013, 100003, 826663, 797593, 959473 };
bitset<959475> filter[5];
inline void insert(const long long key)
{
for ( int i = 0; i < 5; ++i )
filter[i][ key % Primes[i] ] = 1;
}
inline bool find(const long long key)
{
for ( int i = 0; i < 5; ++i )
if ( filter[i][ key % Primes[i] ] == 0 )
return false;
return true;
}
const int N = 276997;
int Q;
int main()
{
freopen("dtcsu.in", "r", stdin);
freopen("dtcsu.out", "w", stdout);
long long nr;
for ( int i = 1; i <= N; ++i )
{
long long X = getNr();
insert(X);
}
long long X = getNr();
Q = X;
int out = 0;
for (;Q;--Q)
{
X = getNr();
bool ok = 1;
for (int i=0;i<5 && ok;++i)
if ( filter[i][ X%Primes[i] ] == 0 )
ok = 0;
if ( ok )
{
X /= (X&(-X));
for ( ; (X/15)*15 == X ; X /= 15 );
for ( ; (X/3)*3 == X ; X /= 3 );
for ( ; (X/5)*5 == X ; X /= 5 );
for ( ; (X/7)*7 == X ; X /= 7 );
for ( ; (X/11)*11 == X ; X /= 11 );
if ( X == 1 ) ++out;
}
}
printf("%d\n",out);
return 0;
}