Skip to content

KerimKochekov/Algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lambda operator (applicable beyond C++11)

Inner-function in Function

	auto function = [](auto x){
		return ...;
	};

Boolean Comporator

    sort(q, q + n, [&](int A, int B) { return A < B; });

Techniques

  1. Sum-Xor property
    $a + b = a \oplus b + 2 (a \land b)$
    $a + b = a | b + a \land b$
    $a \oplus b = a | b - a \land b$

  2. Conjecture: Any even number greater than 2 can be split into two prime numbers

  3. Pragmas for speedup

#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
  1. find all B that B is submask of A (B = A; B > 0; --B, B&=A);

  2. find all D that A is submask of D for (D = A; D < (1 << n); ++D, D |= A)

  3. Rotate board 45 degree by $(x,y) \rightarrow (x+y,y-x)$, so Manhattan distance between two points would be $max(|x1-x2|, |y1-y2|)$.

  4. Find any x,y such that $ax + by = gcd(a,b)$ for given two non-negative integers a and b with Extended Euclidean Algorithm

  5. There is no assumption that n1 and n2 are coprime. Find an integer x that satisfies:

  • $x \equiv a_1 (mod n_1)$
  • $x \equiv a_2 (mod n_2)$

where $d = gcd(n1,n2)$ and $(x', y')$ is retrieved with help of EEA to find $n1x' + n2y' = d$.

  1. $gcd(lcm(x, y_1), lcm(x, y_2), \dots, lcm(x, y_k)) = lcm(x, gcd(y1, y2, \dots, y_k))$
  2. $lcm(gcd(x, y_1), gcd(x, y_2), \dots, gcd(x, y_k)) = gcd(x, lcm(y1, y2, \dots, y_k))$
  3. For any $x \geq y$ the $gcd(x, y) = gcd(x - y, y)$, which can be extended for multiple arguments $gcd(x, y, z, \dots) = gcd(x-y, y, z, \dots)$

About

Nish algorithms and techniques that I like

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published