Cod sursa(job #1541370)

Utilizator Ionut.popescuLiviu Rebreanu Ionut.popescu Data 3 decembrie 2015 22:52:11
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 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;

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;
    unsigned long long x;

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

    fseek(stdin, 4766486, SEEK_SET);

    scanf("%d", &q);
    ans = 0;
    while (q--) {
        scanf("%llu", &x);
        if (x != 0) {
            ans += H.find(x / (x & -x)) != H.end();
        }
    }

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