tutorial6_7 (1)
tutorial6_7 (1)
03 November 2024
OBJECTIVES
Application of the modular approach:
• Breaking down tasks into distinct modules.
Definitions:
1. A closed aliquot sequence is a sequence in which the last element is equal to the first given element
of the sequence. Its order ’e’ is the number of calculated elements in the sequence (excluding the first
one).
2. A perfect number is a number for which the sum of its proper divisors is equal to the number itself.
3. Two numbers A and B are said to be amicable if the sum of the divisors of A is equal to B, and the
sum of the divisors of B is equal to A.
4. A prime number is a number that has only 1 and itself as divisors.
1
Examples:
1. N = 24: Aliquot sequence: 24, 36, 55, 17, 1. N is not prime.
2. N = 11: Aliquot sequence: 11, 1. N is a prime number.
3. N = 28: Aliquot sequence: 28, 28. N is sociable and a perfect number of order 1.
4. N = 220: Aliquot sequence: 220, 284, 220. N is sociable and an amicable number of order 2.
5. N = 12496: Aliquot sequence: 12496, 14288, 15472, 14536, 14264, 12496. N is sociable of order 5.
Task:
Write an algorithn to search for the aliquot sequence that starts with a given number N and detect the case
where N is prime. Additionally, in the case where N is sociable, determine that it is sociable, specify its
order ’e’, and verify if it is perfect or amicable.
Task:
Write an algorithm to perform the following tasks:
1. Convert the number N from base B1 to its decimal (base 10) representation.
• If the number of set bits (1s) is even, change the last bit.
• If the number of set bits is odd, find the rightmost set bit and change the bit to its left.
2
Task:
Develop a solution that generates and displays the first 20 numbers encoded in Gray code.