Cod sursa(job #1017044)

Utilizator VmanDuta Vlad Vman Data 27 octombrie 2013 06:20:19
Problema Dtcsu Scor Ascuns
Compilator cpp Status done
Runda Marime 1.04 kb
#include <cstdio>
#include <bitset>
using namespace std;

#define ll long long

int main() {
    int Q;
    register ll X;
    const ll F = 4194303LL;
    
    bitset<4194304> filter;
    char S[20];
    int total = 0;
    
    freopen("dtcsu.in","r", stdin);
    freopen("dtcsu.out", "w", stdout);
    
    for (int i=0; i<276997; ++i) {
        scanf("%lld", &X);
        filter.set((X>>24) & F);
    }
    
    scanf("%d\n", &Q);

    for (int i=0; i<Q; ++i) {
        static int j;
        fgets(S,20,stdin);
        X = 0LL;
        for (j=0; S[j]!='\n'; ++j)
            X = X*10+S[j]-'0';
        
        if (X==0LL) continue;
        
        if (!filter.test((X>>24) & F)) {
            continue;
        }
        
        static ll a;
        X /= (X&(-X));
        
        while ((a=X/15)*15==X) X = a;
        while (((a=X/3)<<1)+a==X) X = a;
        while (((a=X/5)<<2)+a==X) X = a;
        while ((a=X/7)*7==X) X = a;
        while ((a=X/11)*11==X) X = a;
        total += (X == 1LL);

        
    }
    printf("%d\n", total);
    
    return 0;
}