Professional Documents
Culture Documents
Prepared by :
Rami Zouari
Yessine Jallouli
Number Theory?
- But be aware that solutions can be too advanced for such problems!!!
“Mathematics is the queen of the sciences and
number theory is the queen of mathematics.”
Carl Friedrich Gauss
Why should I bother?
Until the 20th century, number theory was largely seen as only an “art”, with no real
world applications.
With the advent of computers, large breakthroughs in computer science took
advantage of number theory problems
● Security System like in banking securities
● Coding theory
● Making of modular designs
● Memory management system
● Authentication system
● Crypto-currencies
Applications of Number Theory
● GCD / LCM
● Modular arithmetic
● Linear Congruential Equations
● Sieving
● Primality Test
● Factorisation
● Important Arithmetic Functions
● Chinese Remainder Theorem
Greatest common divisors :
Definition :
The greatest common divisors of two or more integers is the largest positive integer that
divides each of the integers without a remainder.
1s method: Brute Forces: Find such integer by checking all number in {1 .. min(n,m) }
Complexity: O(min(n,m))
2nd method : Factorization : The GCD is the product of the common prime factors raised to
the lowest exponent.
C++ implementation :
Definition :
The least common multiple (LCM) of two or more integers is the smallest positive integer that is a multiple
of each of the integers.
The LCM can be found using the following formula: LCM(a,b) = (a * b) / GCD(a,b)
Problem :
Modular Arithmetic
When an operation results in a value that is greater than or equal to the modulus,
the value is "reduced" by subtracting/adding the modulus as many times as
necessary to obtain a positive value less than the modulus.
It is defined as follow:
Complexity : O(1)
Warning : in C/C++ don’t use a+= b%m, that gives a = a + b%m, instead, you should use a = (a+b)%m
Negation / Additive Inverse
It is defined as follow:
It is defined as follow:
Be aware of integer
overflow when multiplying!!!
Power
The modular power can be thought as a repeated multiplication modulo m:
Complexity:
Linear Diophantine Equation
A linear diophantine equation is an equation of the following form:
Complexity : O(nlogn)
Primality test :
Complexity : O(nloglogn)
How to factorize any number using
sieve of Eratosthenes ?
Factorization :
Problem : Given n, output its prime factorization
Complexity : O(log(n))
Advanced methods of factorization :
● Rho factorization
● Pollard p-1
● Quadratic sieve
● General sieve
Counting Divisors
Problem:
Constraints:
- 1 <= m <= 10⁶
- 1 <= pi <= 10⁹
- 1 <= ai <= 10⁹
Sum of Divisors
Problem:
Constraints:
- 1 <= m <= 10⁶
- 1 <= pi <= 10⁹
- 1 <= ai <= 10⁹
Precompute all divisors :
Problem : For each i from 1 to n : precompute the divisors of i.
Euler Totient
Problem:
Given n, how many positive integers x less than n and co-prime with n.
Constraints:
- 1 <= n <= 10⁶
Properties of Euler’s Totient
Multiplicative:
If a and b are co-prime, then
General Formula
Sieving Euler Totient’s values
System of 2 Linear Congruence Equations
It is a system of the following equations:
Chinese Remainder Theorem
The chinese remainder theorem is a method for solving
the following system of congruences: