Euclidian Algorithm Greatest Common Divisor: Problem: How To Find The Greatest
Euclidian Algorithm Greatest Common Divisor: Problem: How To Find The Greatest
11 12 13 14 15 16 17 18 19 20
Solution: One of the efficient way to find all
prime numbers is the Sieve of Erasthostenes 21 22 23 24 25 26 27 28 29 30
which is an ancient algorithm for finding 31 32 33 34 35 36 37 38 39 40
all prime numbers up to any given limit.
41 42 43 44 45 46 47 48 49 50
It does so by iteratively marking
as composite the multiples of each prime, 51 52 53 54 55 56 57 58 59 60
starting with the first prime number, 2. 61 62 63 64 65 66 67 68 69 70
The earliest known reference to the sieve is 71 72 73 74 75 76 77 78 79 80
in Nicomachus of Gerasa’s “Introduction to 81 82 83 84 85 86 87 88 89 90
Arithmetic ” which describes and attributes 91 92 931 94 95 96 97 98 99 100
it to Eratosthenes of Cyrene, a Greek
mathematician.
3
Sieve of Eratosthenes
• Initially, let p equal 2, the smallest prime • Then, turn by turn we equal p to 3,5 and 7 (all
number.Enumerate the multiples of p by prime numbers until √n
counting in increments • All numbers who are not marked are prime
of p from 2p to n(100), and mark them in the numbers.
list (these will be 2p, 3p, 4p, ...; the p itself
should not be marked).
2 3 4 5 6 7 8 9 10 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60 51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80 71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90 81 82 83 84 85 86 87 88 89 90
91 92 931 94 95 96 97 98 99 100 91 92 93 94 95 96 97 98 99 100
4
• That was the ancient algorithm, • We will very if 2 is a deviser of n.
but in our case I will use the • If not, we will verify if every odd
same idea, but I will model it number from the interval [2; √n]
using math is a deviser of n
• I will use a series of numbers • If there is not any number which
starting with 2 and up to √n. is a divisor of n, then n is a
• Now, I will verify if in this interval prime number.
of integer numbers [2; √n] there
is at least a number who divides
n.
Perfect numbers
• Problem: identify if a number is • n is an integer number.
perfect or not.
• We compute all divisors of n:
• Solution: perfect number is a positive
integer that is equal to the sum of its
Dn ={1, d1 , d2 , …. n}
positive divisors, excluding the • Now we compute the sum of
number itself. So, to calculate whether them, wxcluding the number
or not a number is perfect, wee need itself:
to compute its divisors. After this we
will add them, and if the sum is the sum=1+ d1+ d2+….+dx
same as the number, it means te • If sum=n, then n is a perfect
number is perfect. number.