Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Base Code

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)
7 views2 pages

Base Code

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
You are on page 1/ 2

//?

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 (a.second != b.second) {
return a.second < b.second;
}
return a.first < b.first;
}
bool pair_sort(const pair<ll, ll> &a, const pair<ll, ll> &bb)
{
if (a.first == bb.first)
{
return a.second < bb.second;
}
return (a.first > bb.first);
}

ll MOD= 1000000007;

void solving() {

int main() {
// freopen("breedflip.in", "r", stdin);
// freopen("breedflip.out", "w", stdout);
// freopen("overcode.in", "r",stdin);

ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

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

solving();

return 0;
}

You might also like