2. Methodical guidelines / Методичні вказівки
This section is self-contained: it develops the theory of the work’s theme — elementary number theory, two methods of proof, and function evaluation — together with algorithms for the tasks in 4task.md. No outside material is required.
Part A — Number theory
2.1 Divisibility and parity
For integers and , we say divides (written ) if for some integer . An integer is even if and odd otherwise; equivalently, the parity is decided by the remainder :
function parity(n):
if n mod 2 == 0: return "Even"
else: return "Odd"
2.2 Primes and primality testing
A prime is an integer whose only positive divisors are and . To test , it suffices to look for a divisor up to : if with , then , so a composite number always has a factor there.
function isPrime(n):
if n < 2: return false
if n == 2 or n == 3: return true
if n mod 2 == 0: return false
i ← 3
while i*i ≤ n: # test only odd i up to √n
if n mod i == 0: return false
i ← i + 2
return true
This runs in time.
2.3 Greatest common divisor — the Euclidean algorithm
The GCD of and is the largest integer dividing both. It rests on the identity , with : replacing the larger number by the remainder never changes the common divisors and drives the pair to zero.
function gcd(a, b):
a ← |a|; b ← |b|
while b ≠ 0:
(a, b) ← (b, a mod b)
return a
The number of steps is — very fast. For example, : , , , so the GCD is .

2.4 Least common multiple
The LCM is the smallest positive integer that both and divide. It is tied to the GCD by
function lcm(a, b):
if a == 0 or b == 0: return 0
return |a * b| / gcd(a, b) # division is exact: gcd divides a·b
For instance .
2.5 Prime factorization
By the Fundamental Theorem of Arithmetic, every integer has a unique factorization into primes, . Find it by dividing out each prime starting from ; any factor left above at the end is itself prime.
function primeFactorization(n):
factors ← empty list of (prime, exponent)
d ← 2
while d*d ≤ n:
if n mod d == 0:
e ← 0
while n mod d == 0: n ← n / d; e ← e + 1
append (d, e) to factors
d ← d + 1
if n > 1: append (n, 1) to factors # the last prime factor
return factors
Format the result as p1^e1 * p2^e2 * ... (an exponent of may be omitted):
.

2.6 Euler’s totient function
counts the integers in that are coprime to (share no common factor with it). If , then
function totient(n):
result ← n
m ← n
p ← 2
while p*p ≤ m:
if m mod p == 0:
while m mod p == 0: m ← m / p # remove all copies of p
result ← result − result / p # apply factor (1 − 1/p)
p ← p + 1
if m > 1: result ← result − result / m # a final prime factor
return result
For : (the coprime numbers are ).

Part B — Methods of proof
2.7 Direct proof
A direct proof of “if then ” assumes and derives by a chain of definitions and known facts. For the statement “if a number is even, then it is divisible by 2”: assume is even. By the definition of even, for some integer . Then has as a factor, i.e. .
A program can validate such a statement by making the reasoning explicit — recording each step (hypothesis → definition → conclusion) and, as evidence, checking that it holds on a range of concrete inputs. Note that testing instances illustrates but does not replace the general argument.
2.8 Mathematical induction
To prove that holds for all positive integers :
- Base case — prove .
- Inductive step — assume (the induction hypothesis) and prove .
Then holds for every . Worked example — the sum of the first odd numbers is :
- Base: : the sum is . ✓
- Hypothesis: assume .
- Step: adding the next odd number,
A program can facilitate the proof by verifying the base case and checking the inductive step’s algebraic identity (or verifying for as supporting evidence).
Part C — Functions
2.9 Evaluating a function on its domain
A function assigns to each input in its domain a single output; the set of outputs is its range. To evaluate, substitute the value and simplify — for we get . Its domain is all real numbers and its range is . When evaluating, respect the domain: guard against operations that are undefined there (division by zero, the square root of a negative number, and so on).
2.10 Complexity summary
| Routine | Cost |
|---|---|
parity |
|
isPrime (trial division) |
|
gcd (Euclid) |
|
lcm (via GCD) |
|
primeFactorization |
|
totient (via factorization) |