Cod sursa(job #1389946)

Utilizator atatomirTatomir Alex atatomir Data 16 martie 2015 19:05:11
Problema Dtcsu Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.03 kb
#include <iostream>
#include <cstdio>
#include <bitset>
#include <vector>

using namespace std;

class Buffer{
    public:
        long maxBuf,pos;
        vector<char> Buff;

        Buffer(char fileName[],long buffSize){
            freopen(fileName,"r",stdin);
            maxBuf = buffSize; Buff.resize(maxBuf);
            reFill();
        }

        Buffer& operator>>(long long &dest){
            while(!isDigit(Buff[pos])){
                pos++;
                if(pos == maxBuf) reFill();
            }
            dest = 0;
            while(isDigit(Buff[pos])){
                dest = dest*10 + Buff[pos++] - '0';
                if(pos == maxBuf) reFill();
            }
            return *this;
        }

    private:
        bool isDigit(char c){
            return c >= '0' & c <= '9';
        }
        void reFill(){
            fread(&Buff[0],1,maxBuf,stdin); pos = 0;
        }
};


#define cntRead 276997
#define mod 1000000
#define mod1 666013
#define mod2 100003
#define mod3 826663
#define mod4 797593
#define mod5 123761
#define cin fin

long i,cnt;
long long x,n;
bitset<mod+11> B;

inline long long h1(long long x){
    return x%mod1;
}
inline long long h2(long long x){
    return (x+13)%mod2;
}
inline long long h3(long long x){
    return (x+2)%mod3;
}
inline long long h4(long long x){
    return (x+17)%mod4;
}
inline long long h5(long long x){
    return (x+1)%mod5;
}

int main()
{
    Buffer cin("dtcsu.in",1024*256*2);
    freopen("dtcsu.out","w",stdout);

    B.reset();
    for(i=1;i<=cntRead;i++){
        cin >> x;
        if(x&1) {B[h1(x)]=1;B[h2(x)]=1;B[h3(x)]=1;B[h4(x)]=1;B[h5(x)]=1;}
    }

    cin >> n;
    for(i=1;i<=n;i++){
        cin >> x;
        if(x==0) continue;
        x /= (x^(x-1))&x;
        if(B[h1(x)]==1 && B[h2(x)]==1 && B[h3(x)]==1)
            if(B[h4(x)] && B[h5(x)]) {
                while(x%3==0) x/=3;
                while(x%5==0) x/=5;
                while(x%7==0) x/=7;
                while(x%11==0) x/=11;
                if(x==1)cnt++;
            }
    }
    printf("%ld",cnt);

    return 0;
}