Cod sursa(job #1541373)

Utilizator Ionut.popescuLiviu Rebreanu Ionut.popescu Data 3 decembrie 2015 23:00:43
Problema Dtcsu Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.62 kb
#include <bits/stdc++.h>

using namespace std;

const int D[] = {3, 5, 7, 11};
const unsigned long long MAX_V[] = { 333333333333333333ULL, 200000000000000000ULL, 142857142857142857ULL, 90909090909090909ULL };

unsigned long long curr;
int pos;

unordered_set <unsigned long long> H;

inline char getChar() {
    static char buff[65536];
    static int pos = 65536;
    if (pos == 65536) {
        fread_unlocked(buff, 1, 65536, stdin);
        pos = 0;
    }
    return buff[pos++];
}

template <class T>
inline void readVar(T &q) {
    char c;
    do {
        c = getChar();
    } while (!isdigit(c));
    q = 0;
    do {
        q = (q << 1) + (q << 3) + (c - '0');
        c = getChar();
    } while (isdigit(c));
}

void bkt() {
    H.insert(curr);
    for (int i = pos; i < 4; i++) {
        if (curr <= MAX_V[i]) {
            curr = curr * D[i];
            pos = i;
            bkt();
            curr /= D[i];
        }
    }
}

int main(void) {
    freopen("dtcsu.in", "r", stdin);
    freopen("dtcsu.out", "w", stdout);
    int q, ans;
    char c;
    unsigned long long x;

    curr = 1ULL;
    pos = 0;
    bkt();

    int i = 0;
    do {
        do {
            c = getChar();
        } while (!isdigit(c));
        do {
            c = getChar();
        } while (isdigit(c));
        i++;
    } while (i < 276997);

    readVar(q);
    ans = 0;
    while (q--) {
        readVar(x);
        if (x != 0) {
            ans += H.find(x / (x & -x)) != H.end();
        }
    }

    printf("%d\n", ans);
    fclose(stdin);
    fclose(stdout);
    return 0;
}