Pagini recente » Cod sursa (job #615364) | Cod sursa (job #2202506) | Cod sursa (job #2756783) | Cod sursa (job #2017630) | Cod sursa (job #1034015)
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define TOTAL 276997
#define LEN 20
#define ll long long
char s[LEN];
vector< ll > v;
ll p2[6];
int exp[6] = { 1, 2, 4, 8, 16, 32 };
bool is_digit( char c ) {
return c >= '0' && c <= '9';
}
ll get_int( char A[] ) {
ll x = 0;
int i = 0;
while ( is_digit( A[i] ) ) {
x = ( ll ) x * 10 + ( A[i] - '0' );
++i;
}
return x;
}
void read( FILE *fin ) {
for ( int i = 0; i < TOTAL; ++i ) {
fgets( s, LEN, fin );
ll x = get_int( s );
if ( x & 1 )
v.push_back( x );
}
}
void pregen() {
p2[0] = 2;
for ( int i = 1; i < 6; ++i )
p2[i] = ( ll ) p2[i - 1] * p2[i - 1];
}
bool binary_search( ll x ) {
int i, step = 1 << 17;
for ( i = 0; step; step >>= 1 )
if ( i + step < v.size() && v[i + step] <= x )
i += step;
return v[i] == x;
}
int main() {
FILE *fin, *fout;
fin = fopen( "dtcsu.in", "r" );
fout = fopen( "dtcsu.out", "w" );
read( fin );
pregen();
sort( v.begin(), v.end() );
int q, ans = 0;
fscanf( fin, "%d\n", &q );
while ( q ) {
fgets( s, LEN, fin );
ll x = get_int( s );
if ( !( x & 1 ) )
for ( int i = 5; i >= 0; --i )
if ( ( x & ( p2[i] - 1 ) ) == 0 )
x >>= exp[i];
if ( binary_search( x ) )
++ans;
--q;
}
fprintf( fout, "%d\n", ans );
fclose( fin );
fclose( fout );
}