Pagini recente » Cod sursa (job #799889) | Cod sursa (job #120956) | Cod sursa (job #348733) | Cod sursa (job #573608) | Cod sursa (job #1034342)
#include <fstream>
#include <cstring>
using namespace std;
template<const int Size, const int nrHash>
class BloomFilter{
unsigned char B[1 + (Size >> 3)];
inline void setBit(unsigned long long x){
x &= Size;
B[x >> 3] |= 1 << (x & 7);
}
inline bool getBit(unsigned long long x){
x %= Size;
return B[x >> 3] & ( 1 << (x & 7) );
}
inline unsigned long long hash(unsigned long long x, unsigned long long i){
return x + i * i * i;
}
public:
BloomFilter(){
memset(B, 0, sizeof(B));
}
void update(unsigned long long x){
for (unsigned long long i = 0 ; i < nrHash ; i++)
setBit( hash(x, i) );
}
bool query(unsigned long long x){
for (unsigned long long i = 0 ; i < nrHash ; i++)
if (!getBit( hash(x, i) ))
return false;
return true;
}
};
BloomFilter<4682861, 90> B;
const int buffSize = 1 << 17, putere[] = {5, 2, 3, 5, 7, 11};
char buff[buffSize];
void cleanup(unsigned long long& x, unsigned long long p){
if (x < p) return;
if (p < 0x77777777)
cleanup(x, p * p);
unsigned long long a = x / p;
if (a * p == x)
x = a;
}
bool okay(unsigned long long x){
for (int i = 1 ; i <= putere[0] ; i++)
cleanup(x, putere[i]);
return x == 1;
}
ifstream in("dtcsu.in");
ofstream out("dtcsu.out");
int main(){
int times = 276997, ans = 0;
long long x;
while (times--)
in.getline(buff, buffSize);
in >> times;
while (times--){
in >> x;
ans += okay(x);
}
out << ans << "\n";
return 0;
}