Number Theory Min-Max Inclusion-Exclusion The core identities for min-max inclusion-exclusion over finite sets are: $$\max(S) = \sum_{T \subseteq S} (-1)^{|T|+1} \min(T)$$ $$\min(S) = \sum_{T \subseteq S} (-1)^{|T|+1} \max(T)$$ Expanding the summation shows all non-extremal values cancel out. The id...
Sequential Storage Concept of Linear Lists A linear list is a finite sequence of data elements, denoted as $L=(a_0, a_1, \dots, a_{n-1})$, where $L$ is the list name, $a_i$ is the data element, and $n$ is the length of the list. When the elements of linear list $L$ are stored consecutively in comput...
Power Decomposition Given an integer n, output its representation as a sum of distinct powers of two in descending order, or -1 if n is odd. #include <iostream> using namespace std; int main() { int val; cin >> val; if (val % 2 != 0) { cout << "-1"; return 0; } for (int e...