Cod sursa(job #1198509)

Utilizator radustn92Radu Stancu radustn92 Data 15 iunie 2014 21:44:43
Problema Dtcsu Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <cstdio>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;

const int no = 276997;
const int LMAX = (1 << 16);
const int NMAX = (1 << 17);
char buff[LMAX];
int pos = 0, q, N = 5, res;
bitset <NMAX> mark;
int A[] = {2, 3, 5, 7, 11};

inline ll parseLL()
{
	ll x = 0;
	while (!isdigit(buff[pos]))
		if (++pos == LMAX)
			fread(buff, 1, LMAX, stdin), pos = 0;
	
	while (isdigit(buff[pos]))
	{
		x = x * 10 + buff[pos] - '0';
		if (++pos == LMAX)
			fread(buff, 1, LMAX, stdin), pos = 0;
	}
	
	return x;
}

inline ll get(ll x, int i, int j)
{
	x >>= (1LL << (i - 1));
	return x & ((1LL << (j - i + 1)) - 1);
}

void insert_filter(ll x)
{
	mark[get(x, 1, 17)] = 1;
	mark[get(x, 4, 20)] = 1;
}

inline int fails_filter(ll x)
{
	if (!mark[get(x, 1, 17)]) return 1;
	if (!mark[get(x, 4, 20)]) return 1;
	
	return 0;
}

int main()
{
	freopen("dtcsu.in", "r", stdin);
	freopen("dtcsu.out", "w", stdout);
	
	ll x;
	for (int i = 1; i <= no; i++)
	{
		x = parseLL();
		insert_filter(x);
	}
	
	q = parseLL();
	for (int i = 1; i <= q; i++)
	{
		x = parseLL();
		if (!fails_filter(x))
		{
			for (int j = 0; j < N; j++) 
				while (x % A[j] == 0) x /= A[j];
			if (x == 1)
				res++;
		}
	}
	
	printf("%d\n", res);
	return 0;
}