Cod sursa(job #1048672)

Utilizator misinozzz zzz misino Data 6 decembrie 2013 11:13:31
Problema Dtcsu Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.25 kb
#include<fstream>
#include<cstdio>
#include<bitset>
using namespace std;
int sol;
long long x,q;
const int MOD[5]={666013,1000003,826663,797593,959473};
bitset<1000013>h[5];
const int D=200000;
char buf[D];
int poz=D+3;
inline long long ianr()
{
    unsigned long long nr=0;
    while((buf[poz]<'0'||buf[poz]>'9')&&buf[poz]!='-')
    if(++poz>=D)
    fread(buf,D,1,stdin),poz=0;
    while('0'<=buf[poz]&&buf[poz]<='9')
    {
        nr=nr*10+buf[poz]-'0';
        if(++poz>=D)
        fread(buf,D,1,stdin),poz=0;
    }
    return nr;
}
int main()
{
    freopen("dtcsu.in","r",stdin);
    freopen("dtcsu.out","w",stdout);
    long long x;
    for(int i=1;i<=276997;++i)
    {

        x=ianr();
        for(int j=0;j<=4;++j)
        h[j][x%MOD[j]]=1;
    }
    for(q=ianr();q;--q)
    {
        x=ianr();
        bool ok=1;
        for(int j=0;j<=4&&ok;++j)
        if(!h[j][x%MOD[j]])
        ok=0;
        if(ok)
        {
            x/=x&(-x);
            for(;(x/15)*15==x;x/=15);
            for(;(x/3)*3==x;x/=3);
            for(;(x/5)*5==x;x/=5);
            for(;(x/7)*7==x;x/=7);
            for(;(x/11)*11==x;x/=11);
            if(x==1)
            ++sol;
        }
    }
    printf("%d\n",sol);
    return 0;
}