113 C. Double Happiness
Topic Links:
Click here~
First introduce the usage of bitset<>:
< with others have ready >
#include <bister>
Using Std::bitset;
A word definition: A customizable number of bits that can be used as the data type of a binary record.
One, define and initialize
Bitset<n> b; B has n bits, each of which is 0;
Bitset<n> b (U); B is a copy of the unsigned long type U
Bitset<n> b (s); B is a copy of the string object s that contains n-bit strings
Bitset<n> B (S, POS, n); B is a copy of n locations in s that start at the POS position
Bitset<n> b (S,pos); B starts from the POS position of S to the end of S (the value of the note starts at the right end of B)
Note: The number of bits defined by ①n is populated with initial values at initialization, the range of assignments exceeds, and the spare is filled with 0.
②bitset reads a bit set from a string object in a right-to-left order.
Two, operation
B.any (); Does finding B exist in 1?
B.none (); There is no 1 in B?
B.count (); Number of 1 in B
B.size (); The number of bits in B
B[pos]; Accessing the value at POS in B
B.test (POS); Detects if POS is 1 in b
B.set (); Put all positions in B at 1
B.set (POS); Put the POS position in B to 1
B.reset (); Put all positions in B at 0
B.reset (POS); Put the POS position in B to 0
B.flip (); All bits in B are reversed
B.flip (POS); B in the POS at the bits counter
B.to_ulong; Returns a unsigned Long value
OS << b; Put the B-bit set output
/* by Fermat Square and theorem we know that a singular prime can be squared sum, then it must be shaped like the 4k+1 type */#include <iostream> #include <bitset>using namespace std ; const int MAXN = 300000000 + 10;bitset<maxn> primes;int main () { int right,left; while (Cin >> left >> right) { if (left > right) swap (left,right); Primes.set (); for (int i = 3;i * I <= right;i + = 2) if (Primes[i]) for (int j = i * i;j <= right;j + = (i << 1)) primes[ J] = 0; int cnt = (left <= 2&&2 <= right); for (int i = 5;i <= right;i + = 4) if (i >= left && primes[i]) cnt++; cout << cnt << endl; } return 0;}
Filter prime space compression (number theory) && Double Happiness