Cod sursa(job #1032789)

Utilizator fmins123FMI No Stress fmins123 Data 16 noiembrie 2013 01:56:52
Problema Dtcsu Scor Ascuns
Compilator cpp Status done
Runda Marime 2.31 kb
#include <fstream>
#include <algorithm>
#include <string>
#include <bitset>
#include <vector>
#include <functional>

using namespace std;

int Q;
char num[32];
bitset< (1<<16) > bitArray[8];

inline int hash1(const long long &x) {
	return x & ((1LL << 16) - 1);
}

inline int hash2(const long long &x) {
	return x >>	16LL & ((1LL << 16) - 1);
}

inline int hash3(const long long &x) {
	return x >>	32LL & ((1LL << 16) - 1);
}

inline int hash4(const long long &x){
	return x >>	47LL & ((1LL << 16) - 1);
}

inline int hash5(const long long &x) {
	return x >> 5LL & ((1LL << 16) - 1);
}

inline int hash6(const long long &x) {
	return x >>	7LL & ((1LL << 16) - 1);
}

inline int hash7(const long long &x) {
	return x >>	13LL & ((1LL << 16) - 1);
}

inline int hash8(const long long &x){
	return x >>	23LL & ((1LL << 16) - 1);
}


vector< function<int(int)> > hashFunction;

inline void init() {
	hashFunction.push_back(hash1);
	hashFunction.push_back(hash2);
	hashFunction.push_back(hash3);
	hashFunction.push_back(hash4);
	hashFunction.push_back(hash5);
	hashFunction.push_back(hash6);
	hashFunction.push_back(hash7);
	hashFunction.push_back(hash8);

}

inline bool query(const long long &x) {
	for (int k = 0;k < 3;k++) {
		if (bitArray[k][hashFunction[k](x)] == false) {
			return false;
		}
	}
	return true;
}

inline void update(const long long &x) {
	for (int k = 0;k < 8;k++) {
		bitArray[k][hashFunction[k](x)] = true;
	}
}

inline void readSet() {
	for (int i = 0;i < 276997;i++) {
		fgets(num,32,stdin);
		long long value = 0;
		for(int i = 0;num[i] && num[i] != '\n';i++) {
			value = value*10 + (num[i] - '0');
		}
		update(value);
	}
}

inline void solve() {
	int ret = 0;
	const int fc[5] = {2,3,5,7,11};
	scanf("%d\n",&Q);
	for (int i = 0;i < Q;i++) {
		fgets(num,32,stdin);
		long long value = 0;
		for(int i = 0;num[i] != '\0' && num[i] != '\n';i++) {
			value = value * 10 + (num[i] - '0');
		}

		if (query(value)) {
			while ((value & 1) == 0) value >>= 1;
			for (int k = 1;k < 5 && value > 1;k++) {
				while (value % fc[k] == 0) value /= fc[k];
			}

			ret += (value == 1);
		}
	}
	printf("%d\n",ret);
}

int main()
{
	freopen("dtcsu.in","r",stdin);
	freopen("dtcsu.out","w",stdout);
	init();
	readSet();
	solve();
	return 0;
}