Cod sursa(job #1034073)

Utilizator Teodor94Teodor Plop Teodor94 Data 17 noiembrie 2013 17:22:27
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.31 kb
#include <cstdio>
#include <tr1/unordered_map>
 
using namespace std;
using namespace std::tr1;
 
#define TOTAL 276997
#define LEN 20
#define ll long long
 
char s[LEN];
ll p2[6];
unordered_map< int, int > h;
 
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() {
    for ( int i = 0; i < TOTAL; ++i ) {
        gets( s );
        ll x = get_int( s );
 
        if ( x & 1 )
            ++h[x];
    }
}
 
void pregen() {
    p2[0] = 2;
    for ( int i = 1; i < 6; ++i )
        p2[i] = ( ll ) p2[i - 1] * p2[i - 1];
}
 
int main() {
    FILE *fout;
    
    freopen( "dtcsu.in", "r", stdin );
    fout = fopen( "dtcsu.out", "w" );
 
    read();
    pregen();
     
    int q, ans = 0;
    scanf( "%d\n", &q );
    while ( q ) {
        gets( s );
        ll x = get_int( s );
         
        if ( !( x & 1 ) ) {
            for ( int i = 5; i >= 0; --i )
                if ( x % p2[i] == 0 )
                    x /= p2[i];
        }
 
        unordered_map< int, int >::iterator it = h.find( x );
        if ( it != h.end() )
            ++ans;
 
        --q;
    }
     
    fprintf( fout, "%d\n", ans );
    fclose( stdin );
    fclose( fout );
}