I would very much appresiated if someone could look at the code, just to make sure.
Code: Select all
#include <bitset>
class Prime {
std::bitset<0x10000> Pb;
public:
// initializes PB.
Prime():Pb(3) {
// with all bits set exept 0, 1.
Pb.flip();
// outer loop.
for(long n = 0; n < 0xff; n++) {
// find the next set bit (pos n).
for(; Pb[n] != 1; n++) {}
// resets all bit which n divides, exept n.
for(long i = n+n; i <= 0xffff; Pb.reset(i), i += n) {}
}
}
};
Next step is to create a simple function which takes an unsigned long/int as an argument and outputs a bool value, 1 if prime, 0 if not.
I have trouble figuring out the right aproach for this and idea would be appreciated.
Generel advise and stuff are of course allso welcome.
Thanks