Pagini recente » Cod sursa (job #1292892) | Cod sursa (job #1336751) | Cod sursa (job #946966) | Monitorul de evaluare | Cod sursa (job #1044518)
#include <fstream>
#include <bitset>
#include <cstdio>
using namespace std;
FILE *fin=fopen("dtcsu.in", "r");
FILE *fout=fopen("dtcsu.out", "w");
const int maxb=200000;
int ptr=0;
char buff[maxb];
long long GetLong ()
{
long long nr=0;
while (buff[ptr]<'0' || buff[ptr]>'9')
if ((++ptr)>=maxb)
{
ptr=0;
fread(buff, 1, maxb, fin);
}
while (buff[ptr]>='0' && buff[ptr]<='9')
{
nr=nr*10+buff[ptr]-'0';
if ((++ptr)>=maxb)
{
ptr=0;
fread(buff, 1, maxb, fin);
}
}
return nr;
}
const int Mod[5]={666013, 1000003, 826663, 797593, 959473};
const long long MaxV=1LL*1000000000*1000000000;
int Dim[4], Val[5]={15, 3, 5, 7, 11};
long long Pow[4][64];
int N=276997, Q, ANS;
long long X;
bitset<1000010> V[5];
void Add ()
{
for (int i=0; i<5; i++)
V[i][X%Mod[i]]=1;
}
bool Query ()
{
for (int i=0; i<5; i++)
if (!V[i][X%Mod[i]])
return 0;
return 1;
}
int main ()
{
for (int i=0; i<4; i++)
{
Pow[i][0]=1;
while (Pow[i][Dim[i]]<=MaxV/Val[i])
{
++Dim[i];
Pow[i][Dim[i]]=1LL*Val[i]*Pow[i][Dim[i]-1];
}
}
for (int i=1; i<=N; i++)
{
X=GetLong();
Add();
}
Q=GetLong();
int P, U, M, Pos;
for (int q=1; q<=Q; q++)
{
X=GetLong();
if (Query())
{
X/=X&(-X);
for (int i=0; i<5 && X>1; i++)
{
while (X==(X/Val[i])*Val[i])
X/=Val[i];
}
if (X<=1)
ANS++;
}
}
fprintf(fout, "%d\n", ANS);
fclose(fin);
fclose(fout);
return 0;
}