Skip to content

Instantly share code, notes, and snippets.

@orsnaro
Last active October 6, 2023 01:04
Show Gist options
  • Save orsnaro/01d2bd655c3b4e15421a12bcdb4b0ddc to your computer and use it in GitHub Desktop.
Save orsnaro/01d2bd655c3b4e15421a12bcdb4b0ddc to your computer and use it in GitHub Desktop.
some of most used algorithms/ techniques/formulas in Competitive programming feel free to add edit if needed.(note: if you want to print it for any reason I recommend taking the `.pdf` and scale it a little bit smaller to fit in ~25-28 pages)

CP-Beginner-Cheat-Sheets


🗃️INDEX:

CLICK SMALL ARROW TO USE INDEX : Content is Oredered in Alphabetical order. + some usefull Tables at end!




  • E:

  • F:


  • H:


  • J:

  • K:




  • O:



  • R:



  • U - Z:




Algorithm lib functions:

Non-modifying sequence operations:
find
Find value in range (function template)
count
Count appearances of value in range (function template)

Modifying sequence operations:
copy
Copy range of elements (function template)
swap
Exchange values of two objects (function template)
fill
Fill range with value (function template)
remove
Remove value from range (function template)
reverse
Reverse range (function template)
rotate
Rotate left the elements in range (function template)
shuffle
Randomly rearrange elements in range using generator (function template)

Sorting:
sort
Sort elements in range (function template)
is_sorted
Check whether range is sorted (function template)

lower_bound
Return iterator to lower bound (function template)
upper_bound
Return iterator to upper bound (function template)
includes
Test whether sorted range includes another sorted range (function template)
set_union
Union of two sorted ranges (function template)
set_intersection
Intersection of two sorted ranges (function template)
set_difference
Difference of two sorted ranges (function template)

Min/max:
min
Return the smallest (function template)
max
Return the largest (function template)

Other:
lexicographical_compare
Lexicographical less-than comparison (function template)
next_permutation
Transform range to next permutation (function template)
prev_permutation
Transform range to previous permutation (function template)

Bitmasking

//Even test
	if( (n%2) == 9)	// works for +ve values ONLY!
	if( (n&1) == 1)	// works for -ve an +ve values!

//print number in binary ( can also use it to count bits )
void printNumber(int n, int len)
{
	if(!len)
		return ;

	printNumber(n>>1, len-1);	// remove last bit
	cout<<(n&1);				// print last bit
	cnt++; 						//count bits
}

//print number in binary (method 2) -> you also can save it as binary in bitset 

int val = 10;
cout << bitset<bits_no>(val);


// Get bit
int getBit(int num, int idx) {
  return ((num >> idx) & 1) == 1;		// 110100, idx = 4  -->  110 & 1 = 0
}

//Set bit
int setBit1(int num, int idx) {
	return num | (1<<idx);
}

//Reset bit
int setBit0(int num, int idx) {
	return num & ~(1<<idx);				// 110100, idx = 3  -->  110100 & ~000100 = 110100 & 111011
}


//Flip Bit
int flipBit(int num, int idx) {
	return num ^ (1<<idx);
}

//used in Gettig mask subsets + Counting 1 bits + Getting first 1 bit from  right (LSB)
/*
X-1 is very important!

X 	= 840 	= 01101001000
X-1 = 839 	= 01101000111		

X & (X-1) 	= 01101000000		first bit from right removed

X & ~(X-1) 	= 01101001000 & 10010111000 = 00000001000	//get 1st 1 bit from (lsb)
*/

int countNumBits2(int mask) {	//	O(bits Count)		// you also can use '__builtin_popcount()'
	int ret = 0;
	while (mask) 	{
		mask &= (mask-1);
		++ret;	// Simply remove the last bit and so on
	}
	return ret;
}

//GET   subsets  of specific mask
//we know subsets of 101: 101, 100, 001, 000 
void getAllSubMasks(int mask) {

	for(int subMask = mask ; subMask ; subMask = (subMask - 1) & mask)
		printNumber(subMask, 32);	// this code doesn't print 0

	// For reverse: ~subMask&mask = subMask^mask
}


//GET all subsets of length 'X'
// len = 3: 000, 001, 010, 011, 100, 101, 110, 111

void printAllSubsets(int len)	// Remember we did it recursively! This is much SIMPLER!
{
	for (int i = 0; i < (1<<len); ++i)
		printNumber(i, len);

	// For reversed order. Either reverse each item or work from big to small
	//for (int i = (1<<len); i >= 0 ; --i)
	//	printNumber(i, len);
}

Binary-search on int code

polarity method : if low starts at highly possible case it ends at opposite polarity (first impossiple case ) high the same ends at first possible case (high is answer!)

//only edit mid
int ans = 1;
		int l = 1;//re-assure from input ranges
		int h = arr[n - 1] - arr[0]; //re-assure from input ranges
		
		while ( l < h ){
			int m = (l + h + 1) / 2;
			
			if ( h - l <= 4 ){
				for (int i = l; i <= h; i++) //i could be decrementing
					if ( ok(arr , ... , i) )
						ans = i;
				break;
			}

			if ( !ok(arr , ... , m) ) h = m - 1; // `h = m-1;` may be switched with else  line: `l = m + 1;`
			else{ ans = m; l = m + 1; }
		}

Binary-search on float code

 double binarySearch(double st, double en){
    double L = 0 , R = en, mid;
    while(R - L > eps){ // eps: some very small value (dependent on the problem)
      mid = L + (R - L) / 2;
      if(valid(mid))
        L = mid;
      else
        R = mid;
    }
    return L + (R - L) / 2; // mid
 }

Backtracking code&rules

( maze and the general code template of backtracking ) :

// Typical backtracking procedure ( base case - state - transition )
void recursion(state s)
{
   if( base(s) )
   	return ;

   for each substate ss
   	mark ss

   	recursion (ss)

   	unmark ss
}


//example : maze
char maze(MAX , MAX){
//.SX..
//..X.E
//....X
//X.XX.
}
bool vis[MAX][MAX];
bool findEnd2(int r, int c)	// Recursion State: r, c	and FULL visted array
{
   if( !valid(r, c) || maze[r][c] == 'X' || vis[r][c] == 1)
   	return false;		// invalid position or block position


   vis[r][c] = 1;	// we just visited it, don't allow any one back to it

   if( maze[r][c] =='E')
   	return true;	// we found End

   // Try the 4 neighbor cells
    if(findEnd2(r, c-1)) return true;  	// search up
   if(findEnd2(r, c+1)) return true; 	// search down
   if(findEnd2(r-1, c)) return true;  	// search left
   if(findEnd2(r+1, c)) return true;  	// search right

   vis[r][c] = 0;	// undo marking, other paths allowed to use it now

   // Can't find a way for it!
   return false;
}
example of backtraking that i studied before:  
https://www.geeksforgeeks.org/write-a-c-program-to-print-all-permutations-of-a-given-string/

Check if specific number is prime ( not seive )

bool isPrime(int n) { // O(sqrt(n))
    if (n == 2) return true;
    if (n < 2 || !(n & 1)) return false;
    for (int i = 3; i * i <= n; i += 2) {
        if (n % i == 0) return false;
    }
    return true;
}

Compare function example code

//lamda function (sort vector of pairs)
vector<pair<int, stack<int>>> arr(mp.begin() , mp.end());
sort(arr.begin(), arr.end(), [](const auto& a, const auto& b) { return a.first > b.first;});

//compare function ( sort  desc. by first  if equal sort desc. by second)
bool comp (  pair<int, int> &a , pair<int,int> &b){
	if ( a.F != b.F ){
		return a.F > b.F;
	}else{
		return a.S > b.S;
	}
}

Cout formating

Hex output cout <<hex << number << dec; , Binary output cout << bitset<sz>number;

Diagonally navigation 2D array:

//traverse and print all zeroes in main diagonal 
for (int step = 0 ; step < row; step++)
cout << arr[step][step]; 

//traverse and print all zeroes in anti diagonal 
for (int step = 0 ; step < row; step++)
cout << arr[step][colm - 1 - step];

Dijkestra algorithm [TODO]


Fast power code

// in iterative style
ll fastPow(ll base, ll power /*, ll m*/) { // O(log[power])
  ll ans = 1;
  while (power) {
    if (power & 1)
      ans = (ans * base); // if we have mod => ans = (ans * base) % m
    base = (base * base); // base = (base * base) % m
    power >>= 1;
  }
  return ans;
}
//in RECURSIVE style
int fast_pow(int x,int n) {
    if(n==0) return 1;
    //n is even
    else if(n%2 == 0)        
        return fast_pow(x*x,n/2);
    //n is odd
    else                             
        return x * fast_pow(x*x,(n-1)/2);
}

Factors of a number

void printDivisors(int n)
{
    // Note that this loop runs till square root
    for (int i=1; i<=sqrt(n); i++)
    {
        if (n%i == 0)
        {
            // If divisors are equal, print only one(case of n being complete square)
            if (n/i == i)
                cout <<" "<< i;
  
            else // Otherwise print both
                cout << " "<< i << " " << n/i;
        }
    }
}

gcd and lcm

gcd <data_type> (x,y);
__gcd(x,y);
 int lcm = (x * y) / gcd(x,y); 

Inclusion Exclusion:

|A ∪ B ∪ C| = |A| + |B| + |C| - |A ∩ B| - |B ∩ C| - |A ∩ C| + |A ∩ B ∩ C|

--- > ## log for counting number of bits or digits: ```cpp int n = 124123123; int no_bits = floor( log2(n) ) + 1; // gets no of bits

int no_dig = floor( log10(n) ) + 1; // get no of digits

---

> ## Mod properties:

	( a + b) % c = ( ( a % c ) + ( b % c ) ) % c
	( a * b) % c = ( ( a % c ) * ( b % c ) ) % c
	( a – b) % c = ( ( a % c ) – ( b % c ) ) % c
	
---

> ## nPr , nCr:

* ### in nPr ( any re-order of same choosen elements increases all nPr count )

* ### nCr is alwyas less than nPr (diffrent arrangement of same choosen elements does not increase nCr counter more than once for same elements)

![table showing fomulas for compinatorics](https://ucarecdn.com/fcd7bbfc-2949-488d-ada4-36a0ff1609fc/nprVSncr.png)

---
 > ## next_permutation(start,end) 
 
 array must be sorted inc. to get  all permutations count  and arrangment (summary: to get all permutaion start from smallest arrangement in lexical order)

---
> ## Problem constraints Hints:

 ![ a table showing how to determine possible solution technique from constrains of a problem](https://ucarecdn.com/ee1810ef-402f-4941-9562-f74c5fa1c4e8/hints_from_constrains.png)

---
> ## Prime factorization (to get all prime factors of a number)
```cpp
vector<int> v;
vector<int> prime_factors(int n){

	while ( (n & 1) == 0 ){//if even  note: '==' has higher precedence than '&'  
		v.push_back(2);
		n >>= 1;
	}

	// n must be odd at this point. So we can skip
    // one element (Note i = i +2)
	for(int i = 3; i <= n / i; i += 2){
		// While i divides n, print i and divide n
		while (n % i == 0){
			v.push_back(i);
			n /= i;
		}
	}

	// This condition is to handle the case when n
    // is a prime number greater than 2
	if (n > 2) v.push_back(n); 

	return v;
}

printf() and scanf() specially with floating point fixed precision

scanf("%d", &testInteger);
printf("Number = %d", testInteger); //%f for float  %lf for double %c for char 

//control floating point 
//9dig before the point + the point then 6dig after the point) -> 123456789.123456
printf("%10.6lf",myDoubleNum);

Quadratic function solver code

// x = (-b ± sqrt(b^2 - 4ac) ) / 2a;
float a, b, c, x1, x2, discriminant, realPart, imaginaryPart;
    cin >> a >> b >> c;
    discriminant = b*b - 4*a*c;
    
    if (discriminant > 0) {
        x1 = (-b + sqrt(discriminant)) / (2*a);
        x2 = (-b - sqrt(discriminant)) / (2*a);
    }
    
    else if (discriminant == 0) {
        x1 = -b/(2*a);
    }

    else {
        realPart = -b/(2*a);
        imaginaryPart =sqrt(-discriminant)/(2*a);
    }

STD libs:

if you cant use bits/stdc++.h . those are most of want you will need:

Standard C++ header Equivalent in previous versions <iostream><limits><utility><cmath><ctype><algorithm><bitset><deque><iterator><list><map><queue><set><stack><unordered_map><unordered set><vector>

STLs:

  • Complexity of stack vs queue vs array :

table of complexties for different operations on  different DS

  • Bitset bitset<size> name(init)

    (note1: container member functions (note: element with index 0 is the RMB) (note2 : bistset can be initialized using string of bits "binary string" ): bitset<size> variable_name("BINARY_STRING");

    Bit access

    operator[]
    Access bit (public member function)
    count
    Count bits set (public member function)
    size
    Return size (public member function)
    test
    Return bit value (public member function)
    any
    Test if any bit is set (public member function)
    none
    Test if no bit is set (public member function)
    all
    Test if all bits are set (public member function)

    Bit operations

    set
    Set bits (public member function)
    reset
    Reset bits (public member function)
    flip
    Flip bits (public member function)

    Bitset operations

    to_string
    Convert to string (public member function)
    to_ulong
    Convert to unsigned long integer (public member function)
    to_ullong
    Convert to unsigned long long (public member function)
  • Vector

    Iterators:
    begin
    Return iterator to beginning (public member function)
    end
    Return iterator to end (public member function)
    rbegin
    Return reverse iterator to reverse beginning (public member function)
    rend
    Return reverse iterator to reverse end (public member function)
    Capacity:
    size
    Return size (public member function)
    max_size
    Return maximum no. of elements vector can ever hold (effected by machine and ram) (public member function)
    resize
    Change size (public member function)
    capacity
    Return size of allocated storage capacity (public member function)
    empty
    Test whether vector is empty (public member function)
    reserve
    Request a change in capacity (public member function)
    shrink_to_fit
    Shrink to fit (public member function)

    Element access:
    operator[]
    Access element (public member function)
    at
    Access element (public member function)
    front
    Access first element (public member function)
    back
    Access last element (public member function)
    data
    Access data (public member function)

    Modifiers:
    assign
    Assign vector content (public member function)
    push_back
    Add element at the end (public member function)
    pop_back
    Delete last element (public member function)
    insert
    Insert elements (public member function)
    erase
    Erase elements (public member function)
    swap
    Swap content (public member function)
    clear
    Clear content (public member function)
    emplace
    Construct and insert element (public member function)
    emplace_back
    Construct and insert element at the end (public member function)
  • Stack

    empty
    Test whether container is empty (public member function)
    size
    Return size (public member function)
    top
    Access next element (public member function)
    push
    Insert element (public member function)
    emplace
    Construct and insert element (public member function)
    pop
    Remove top element (public member function)
    swap
    Swap contents (public member function)

    Non-member function overloads

    relational operators
    Relational operators for stack (function)
    swap (stack)
    Exchange contents of stacks (public member function)

  • Queue

    empty
    Test whether container is empty (public member function)
    size
    Return size (public member function)
    front
    Access next element (public member function)
    back
    Access last element (public member function)
    push
    Insert element (public member function)
    emplace
    Construct and insert element (public member function)
    pop
    Remove next element (public member function)
    swap
    Swap contents (public member function)

    Non-member function overloads

    relational operators
    Relational operators for queue (function)
    swap (queue)
    Exchange contents of queues (public member function)

  • Deque

    Iterators:
    begin
    Return iterator to beginning (public member function)
    end
    Return iterator to end (public member function)
    rbegin
    Return reverse iterator to reverse beginning (public member function)
    rend
    Return reverse iterator to reverse end (public member function)
    cbegin
    Return const_iterator to beginning (public member function)
    cend
    Return const_iterator to end (public member function)
    crbegin
    Return const_reverse_iterator to reverse beginning (public member function)
    crend
    Return const_reverse_iterator to reverse end (public member function)

    Capacity:
    size
    Return size (public member function)
    max_size
    Return maximum size (public member function)
    resize
    Change size (public member function)
    empty
    Test whether container is empty (public member function)
    shrink_to_fit
    Shrink to fit (public member function)

    Element access:
    operator[]
    Access element (public member function)
    at
    Access element (public member function)
    front
    Access first element (public member function)
    back
    Access last element (public member function)

    Modifiers:
    assign
    Assign container content (public member function)
    push_back
    Add element at the end (public member function)
    push_front
    Insert element at beginning (public member function)
    pop_back
    Delete last element (public member function)
    pop_front
    Delete first element (public member function)
    insert
    Insert elements (public member function)
    erase
    Erase elements (public member function)
    swap
    Swap content (public member function)
    clear
    Clear content (public member function)
    emplace
    Construct and insert element (public member function)
    emplace_front
    Construct and insert element at beginning (public member function)
    emplace_back
    Construct and insert element at the end (public member function)

    Non-member functions overloads

    relational operators
    Relational operators for deque (function)
    swap
    Exchanges the contents of two deque containers (function template)
  • Priority_Queue

    empty
    Test whether container is empty (public member function)
    size
    Return size (public member function)
    top
    Access top element (public member function)
    push
    Insert element (public member function)
    emplace
    Construct and insert element (public member function)
    pop
    Remove top element (public member function)
    swap
    Swap contents (public member function)

    Non-member function overloads

    swap (queue)
    Exchange contents of priority queues (public member function)

  • Map ( multimap , unordered_map , unordered_multimap )ordered search : O(log n) unordered search: O(1)

    Iterators:
    begin
    Return iterator to beginning (public member function)
    end
    Return iterator to end (public member function)
    rbegin
    Return reverse iterator to reverse beginning (public member function)
    rend
    Return reverse iterator to reverse end (public member function)
    cbegin
    Return const_iterator to beginning (public member function)
    cend
    Return const_iterator to end (public member function)
    crbegin
    Return const_reverse_iterator to reverse beginning (public member function)
    crend
    Return const_reverse_iterator to reverse end (public member function)

    Capacity:
    empty
    Test whether container is empty (public member function)
    size
    Return container size (public member function)
    max_size
    Return maximum size (public member function)

    Element access:
    operator[]
    Access element (public member function)
    at
    Access element (public member function)

    Modifiers:
    insert
    Insert elements (public member function)
    erase
    Erase elements (public member function)
    swap
    Swap content (public member function)
    clear
    Clear content (public member function)
    emplace
    Construct and insert element (public member function)
    emplace_hint
    Construct and insert element with hint (public member function)

    Operations:
    find
    Get iterator to element (public member function)
    count
    Count elements with a specific key (public member function)
    lower_bound
    Return iterator to lower bound (public member function)
    upper_bound
    Return iterator to upper bound (public member function)
    equal_range
    Get range of equal elements (public member function)
  • Set ( multiset , unordered_set , unordered_multiset ) ordered search : O(log n) unordered search: O(1)

    Iterators:
    begin
    Return iterator to beginning (public member function)
    end
    Return iterator to end (public member function)
    rbegin
    Return reverse iterator to reverse beginning (public member function)
    rend
    Return reverse iterator to reverse end (public member function)
    cbegin
    Return const_iterator to beginning (public member function)
    cend
    Return const_iterator to end (public member function)
    crbegin
    Return const_reverse_iterator to reverse beginning (public member function)
    crend
    Return const_reverse_iterator to reverse end (public member function)

    Capacity:
    empty
    Test whether container is empty (public member function)
    size
    Return container size (public member function)
    max_size
    Return maximum size (public member function)

    Modifiers:
    insert
    Insert element (public member function)
    erase
    Erase elements (public member function)
    swap
    Swap content (public member function)
    clear
    Clear content (public member function)
    emplace
    Construct and insert element (public member function)
    emplace_hint
    Construct and insert element with hint (public member function)

    Operations:

    find
    Get iterator to element (public member function)
    count
    Count elements with a specific value (public member function)
    lower_bound
    Return iterator to lower bound (public member function)
    upper_bound
    Return iterator to upper bound (public member function)
    equal_range
    Get range of equal elements (public member function)

String functions and member functions:

string class member functions cctype.h library functions


Seive code

Complexity: O(nLog(Log(n)))

int N = 1e6 + 5;
vector<bool> is_prime(N, true);

void sieve(ll sz){

	is_prime[0] = is_prime[1] = false; //not primes ( 1 is rarely  considered prime )

	for (int i = 2; i * i <= n; i++) { // or 'i <= i/n' if 'i' could OF
		if (is_prime[i]) {
			for (int j = i * i; j <= n; j += i)
				is_prime[j] = false;
		}
	}
}

Summation formulas

summation formulas


sqrt(), sqrtl(), sqrtf(), log(), logf(), logl():

may have accuracy and approximation issues at very big or small numbers (hard to predict when it will be off by +1 or -1   so you can handle its errors)

Substring vs subsequence vs subarray

two tables comparing between substring,subsequence and subarray


Setprecision

cout << fixed << setprecision(num_after_point) << float_val;

Template CP:

to compile-run : g++ main.cpp -o main.exe && main.exe or clang++ main.cpp -o main.exe && main.exe

// #include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define Txtio   freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fastio                                                                 \
   ios_base::sync_with_stdio(false);                                           \
   cin.tie(nullptr);                                                           \
   cout.tie(nullptr);

#define F first
#define S second
using ll = long long;
using ull = unsigned long long;
const ll LM = LONG_LONG_MAX;
const int N = 2e6 + 5, M = INT32_MAX;
// int arr[N];
int main(void) {
	// Txtio;
   fastio; // disable with 'printf() , scanf()'
   int t = 1;
   // cin >> t;
   while (t--) {
   }     
	return 0;  
}

2D prefix sum code

  • Code:
int arr[N+1][M+1]={0}, prefixSum[N+1][M+1];
  int n,m;
  cin>>n>>m;
  for(int i=1; i<=n; i++)
    for(int j=1; j<=m; j++)
      cin>>arr[i][j];
 
  for(int i=1; i<=n; i++)
    for(int j=1; j<=m; j++)
      prefixSum[i][j]=arr[i][j] + prefixSum[i-1][j] + prefixSum[i][j-1] - prefixSum[i-1][j-1];
 
 
  int r1,c1, r2,c2;
  cin>>r1>>c1>>r2>>c2; // one-based
  cout<<prefixSum[r2][c2] - prefixSum[r1-1][c2] - prefixSum[r2][c1-1] + prefixSum[r1-1][c1-1]<<'\n';
  • after constructing final Commulative array :

slide shows how to get a sum from the final C array


TABLES

table: First 1000 primes

 12345678910
1 - 102357111317192329
11 - 2031374143475359616771
21 - 307379838997101103107109113
31 - 40127131137139149151157163167173
41 - 50179181191193197199211223227229
51 - 60233239241251257263269271277281
61 - 70283293307311313317331337347349
71 - 80353359367373379383389397401409
81 - 90419421431433439443449457461463
91 - 100467479487491499503509521523541
101 - 110547557563569571577587593599601
111 - 120607613617619631641643647653659
121 - 130661673677683691701709719727733
131 - 140739743751757761769773787797809
141 - 150811821823827829839853857859863
151 - 160877881883887907911919929937941
161 - 17094795396797197798399199710091013
171 - 1801019102110311033103910491051106110631069
181 - 1901087109110931097110311091117112311291151
191 - 2001153116311711181118711931201121312171223
201 - 2101229123112371249125912771279128312891291
211 - 2201297130113031307131913211327136113671373
221 - 2301381139914091423142714291433143914471451
231 - 2401453145914711481148314871489149314991511
241 - 2501523153115431549155315591567157115791583
251 - 2601597160116071609161316191621162716371657
261 - 2701663166716691693169716991709172117231733
271 - 2801741174717531759177717831787178918011811
281 - 2901823183118471861186718711873187718791889
291 - 3001901190719131931193319491951197319791987
301 - 3101993199719992003201120172027202920392053
311 - 3202063206920812083208720892099211121132129
321 - 3302131213721412143215321612179220322072213
331 - 3402221223722392243225122672269227322812287
341 - 3502293229723092311233323392341234723512357
351 - 3602371237723812383238923932399241124172423
361 - 3702437244124472459246724732477250325212531
371 - 3802539254325492551255725792591259326092617
381 - 3902621263326472657265926632671267726832687
391 - 4002689269326992707271127132719272927312741
401 - 4102749275327672777278927912797280128032819
411 - 4202833283728432851285728612879288728972903
421 - 4302909291729272939295329572963296929712999
431 - 4403001301130193023303730413049306130673079
441 - 4503083308931093119312131373163316731693181
451 - 4603187319132033209321732213229325132533257
461 - 4703259327132993301330733133319332333293331
471 - 4803343334733593361337133733389339134073413
481 - 4903433344934573461346334673469349134993511
491 - 5003517352735293533353935413547355735593571
501 - 5103581358335933607361336173623363136373643
511 - 5203659367136733677369136973701370937193727
521 - 5303733373937613767376937793793379738033821
531 - 5403823383338473851385338633877388138893907
541 - 5503911391739193923392939313943394739673989
551 - 5604001400340074013401940214027404940514057
561 - 5704073407940914093409941114127412941334139
571 - 5804153415741594177420142114217421942294231
581 - 5904241424342534259426142714273428342894297
591 - 6004327433743394349435743634373439143974409
601 - 6104421442344414447445144574463448144834493
611 - 6204507451345174519452345474549456145674583
621 - 6304591459746034621463746394643464946514657
631 - 6404663467346794691470347214723472947334751
641 - 6504759478347874789479347994801481348174831
651 - 6604861487148774889490349094919493149334937
661 - 6704943495149574967496949734987499349995003
671 - 6805009501150215023503950515059507750815087
681 - 6905099510151075113511951475153516751715179
691 - 7005189519752095227523152335237526152735279
701 - 7105281529753035309532353335347535153815387
711 - 7205393539954075413541754195431543754415443
721 - 7305449547154775479548355015503550755195521
731 - 7405527553155575563556955735581559156235639
741 - 7505641564756515653565756595669568356895693
751 - 7605701571157175737574157435749577957835791
761 - 7705801580758135821582758395843584958515857
771 - 7805861586758695879588158975903592359275939
781 - 7905953598159876007601160296037604360476053
791 - 8006067607360796089609161016113612161316133
801 - 8106143615161636173619761996203621162176221
811 - 8206229624762576263626962716277628762996301
821 - 8306311631763236329633763436353635963616367
831 - 8406373637963896397642164276449645164696473
841 - 8506481649165216529654765516553656365696571
851 - 8606577658165996607661966376653665966616673
861 - 8706679668966916701670367096719673367376761
871 - 8806763677967816791679368036823682768296833
881 - 8906841685768636869687168836899690769116917
891 - 9006947694969596961696769716977698369916997
901 - 9107001701370197027703970437057706970797103
911 - 9207109712171277129715171597177718771937207
921 - 9307211721372197229723772437247725372837297
931 - 9407307730973217331733373497351736973937411
941 - 9507417743374517457745974777481748774897499
951 - 9607507751775237529753775417547754975597561
961 - 9707573757775837589759176037607762176397643
971 - 9807649766976737681768776917699770377177723
981 - 9907727774177537757775977897793781778237829
991 - 10007841785378677873787778797883790179077919

table: ASCII code

Char Number Description
  0 - 31 Control characters (see below)
  32 space
! 33 exclamation mark
" 34 quotation mark
# 35 number sign
$ 36 dollar sign
% 37 percent sign
& 38 ampersand
' 39 apostrophe
( 40 left parenthesis
) 41 right parenthesis
* 42 asterisk
+ 43 plus sign
, 44 comma
- 45 hyphen
. 46 period
/ 47 slash
0 48 digit 0
1 49 digit 1
2 50 digit 2
3 51 digit 3
4 52 digit 4
5 53 digit 5
6 54 digit 6
7 55 digit 7
8 56 digit 8
9 57 digit 9
: 58 colon
; 59 semicolon
< 60 less-than
= 61 equals-to
> 62 greater-than
? 63 question mark
@ 64 at sign
A 65 uppercase A
B 66 uppercase B
C 67 uppercase C
D 68 uppercase D
E 69 uppercase E
F 70 uppercase F
G 71 uppercase G
H 72 uppercase H
I 73 uppercase I
J 74 uppercase J
K 75 uppercase K
L 76 uppercase L
M 77 uppercase M
N 78 uppercase N
O 79 uppercase O
P 80 uppercase P
Q 81 uppercase Q
R 82 uppercase R
S 83 uppercase S
T 84 uppercase T
U 85 uppercase U
V 86 uppercase V
W 87 uppercase W
X 88 uppercase X
Y 89 uppercase Y
Z 90 uppercase Z
[ 91 left square bracket
\ 92 backslash
] 93 right square bracket
^ 94 caret
_ 95 underscore
` 96 grave accent
a 97 lowercase a
b 98 lowercase b
c 99 lowercase c
d 100 lowercase d>
e 101 lowercase e>
f 102 lowercase f>
g 103 lowercase g>
h 104 lowercase h>
i 105 lowercase i>
j 106 lowercase j>
k 107 lowercase k>
l 108 lowercase l>
m 109 lowercase m>
n 110 lowercase n>
o 111 lowercase o>
p 112 lowercase p>
q 113 lowercase q>
r 114 lowercase r>
s 115 lowercase s>
t 116 lowercase t>
u 117 lowercase u>
v 118 lowercase v>
w 119 lowercase w>
x 120 lowercase x>
y 121 lowercase y>
z 122 lowercase z>
{ 123 left curly brace>
| 124 vertical bar>
} 125 right curly brace>
~ 126 tilde>

table: Binary numbers (1-256)

No.Binary Number
1011100101
1021100110
1031100111
1041101000
1051101001
1061101010
1071101011
1081101100
1091101101
1101101110
1111101111
1121110000
1131110001
1141110010
1151110011
1161110100
1171110101
1181110110
1191110111
1201111000
1211111001
1221111010
1231111011
1241111100
1251111101
1261111110
1271111111
12810000000
12910000001
13010000010
13110000011
13210000100
13310000101
13410000110
13510000111
13610001000
13710001001
13810001010
13910001011
14010001100
14110001101
14210001110
14310001111
14410010000
14510010001
14610010010
14710010011
14810010100
14910010101
15010010110
15110010111
15210011000
15310011001
15410011010
15510011011
15610011100
15710011101
15810011110
15910011111
16010100000
16110100001
16210100010
16310100011
16410100100
16510100101
16610100110
16710100111
16810101000
16910101001
17010101010
17110101011
17210101100
17310101101
17410101110
17510101111
17610110000
17710110001
17810110010
17910110011
18010110100
18110110101
18210110110
18310110111
18410111000
18510111001
18610111010
18710111011
18810111100
18910111101
19010111110
19110111111
19211000000
19311000001
19411000010
19511000011
19611000100
19711000101
19811000110
19911000111
20011001000
20111001001
20211001010
20311001011
20411001100
20511001101
20611001110
20711001111
20811010000
20911010001
21011010010
21111010011
21211010100
21311010101
21411010110
21511010111
21611011000
21711011001
21811011010
21911011011
22011011100
22111011101
22211011110
22311011111
22411100000
22511100001
22611100010
22711100011
22811100100
22911100101
23011100110
23111100111
23211101000
23311101001
23411101010
23511101011
23611101100
23711101101
23811101110
23911101111
24011110000
24111110001
24211110010
24311110011
24411110100
24511110101
24611110110
24711110111
24811111000
24911111001
25011111010
25111111011
25211111100
25311111101
25411111110
25511111111
256100000000

table: Ranges of int and double datatypes

(use `sizeof(var)` to know exact size in your machine in bytes)
Type Typical Bit Width Typical Range
char 1byte -127 to 127 or 0 to 255
unsigned char 1byte 0 to 255
signed char 1byte -127 to 127
int 4bytes -2147483648 to 2147483647 [~10e9]
unsigned int 4bytes 0 to 4294967295
signed int 4bytes -2147483648 to 2147483647
short int 2bytes -32768 to 32767
unsigned short int 2bytes 0 to 65,535
signed short int 2bytes -32768 to 32767
long int 8bytes -9223372036854775808 to 9223372036854775807
signed long int 8bytes same as long int
unsigned long int 8bytes 0 to 18446744073709551615
long long int 8bytes -(2^63) to (2^63)-1 [~10e19]
unsigned long long int 8bytes 0 to 18,446,744,073,709,551,615
float 4bytes
double 8bytes
long double 12bytes
wchar_t 2 or 4 bytes 1 wide character

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment