Ex 1 Even vs Odd integers

Write a Python function classify(n: int) -> str that returns "even" if $n$ is even and "odd" otherwise.

Hint: An integer $n$ is even iff $n \bmod 2 = 0$.
Ex 2 Primality Test primes

Implement is_prime(n: int) -> bool using trial division up to $\lfloor\sqrt{n}\rfloor$.

Hint: Use math.isqrt(n) from the standard library to compute $\lfloor\sqrt{n}\rfloor$ exactly.
Ex 3 Modular Arithmetic mod

Write mod_ops(a, b, m) -> dict that returns a dictionary with keys "add", "sub", and "mul" holding $(a+b)\bmod m$, $(a-b)\bmod m$, and $(a \cdot b)\bmod m$ respectively.

Ex 4 GCD and LCM divisibility

Implement lcm(a, b) using Python's math.gcd, then verify the identity:

$$\gcd(a,b)\times \text{lcm}(a,b) = a \times b$$

Test with pairs $(12,8)$, $(100,75)$, and $(17,13)$. Print the GCD, LCM, and whether the identity holds for each pair.

Ex 5 Fibonacci Sequence sequences

Write fibonacci(n: int) -> list[int] that generates the first $n$ Fibonacci numbers iteratively (no recursion).

Hint: Handle the edge case $n \le 0$ by returning an empty list.
Ex 6 Counting Divisors divisibility

Write divisors(n: int) -> list[int] that returns all positive divisors of $n$ in sorted order.

Ex 7 Binomial Coefficient & Pascal's Identity combinatorics

Implement $C(n,k)$ (n-choose-k) without using math.comb, then verify Pascal's identity:

$$C(n,k) = C(n-1,k-1) + C(n-1,k)$$

Hint: Use the multiplicative formula and reduce $k$ to $\min(k,\, n-k)$ to minimise iterations.
Ex 8 Power Set sets · counting

Write power_set(s: list) -> list that returns the list of all subsets of $s$.

Ex 9 Sieve of Eratosthenes primes

Implement sieve(N: int) -> list[int] that returns all primes $\le N$ using the Sieve of Eratosthenes (boolean array).

Hint: Start crossing off multiples of $i$ from $i^2$, not from $2i$. Only iterate $i$ up to $\lfloor\sqrt{N}\rfloor$.
Ex 10 Arithmetic & Geometric Sequences sequences

Write arithmetic(start, step, n) and geometric(start, ratio, n) that each return a list of $n$ terms.

Ex 11 Brute-Force Truth Table logic

Write brute_truth_table(expr_fn, var_names) that prints a truth table for any boolean function of $n$ variables by enumerating all $2^n$ combinations.