0% found this document useful (0 votes)
3 views2 pages

Bitmask and Prime Number Functions

The document contains a collection of useful bitmask operations and a prime-checking function in C++. It also includes utility functions for sorting pairs and performing ceiling division. The main function sets up the environment for input/output and calls a solving function, which is currently empty.

Uploaded by

obadamomani60
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Bitmask and Prime Number Functions

The document contains a collection of useful bitmask operations and a prime-checking function in C++. It also includes utility functions for sorting pairs and performing ceiling division. The main function sets up the environment for input/output and calls a solving function, which is currently empty.

Uploaded by

obadamomani60
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

//?

bitmask useful formulas


// x | (1 << j) //! (Set) turns on the j-th bit
// x & ~(1 << j) OR ~(~x | (1 << j)) //! (Clear) turns off the j-th bit
// x ^ (1 << j) //! (Toggle) flips a bit
// x & (1 << j) == number //! (Check) number == 0 ? isOff : isOn (1 << j);
// (((~x)+1) & x) //! keeps LSB
// x & -x == LSB //! gets LSB
// (x & (x-1)) //! turns off LSB
// (1 << n) - 1 //! turns on all bits
// (1 << n) == //! number of subsets
// for (x = y; x > 0; x = (y & (x - 1))) //! iterate through all subsets of y without the empty set

#include <bits/stdc++.h>

bool isprime(int n) {
if (n <= 1) {
return false;
}
if (n == 2 || n == 3) {
return true;
}
if (n % 2 == 0 || n % 3 == 0) {
return false;
}
for (int i = 5; i * i <= n; i = i + 6) {
if (n % i == 0 || n % (i + 2) == 0) {
return false;
}
}

return true;
}
using namespace std;
#define ll long long
#define inf 1e18
ll ceil_division(ll a, ll b) { return (a + b - 1) / b; }
bool comparePairs(const std::pair<long long, long long>& a, const std::pair<long long, long long>& b) {
if ([Link] != [Link]) {
return [Link] < [Link];
}
return [Link] < [Link];
}
bool pair_sort(const pair<ll, ll> &a, const pair<ll, ll> &bb)
{
if ([Link] == [Link])
{
return [Link] < [Link];
}
return ([Link] > [Link]);
}

ll MOD= 1000000007;

void solving() {

int main() {
// freopen("[Link]", "r", stdin);
// freopen("[Link]", "w", stdout);
// freopen("[Link]", "r",stdin);

ios::sync_with_stdio(0);
[Link](0);
[Link](0);

// ll t;
// cin >> t;
// while (t--) {
// solving();
// }

solving();

return 0;
}

You might also like