## Friday, September 11, 2020

Solution Exercise 84: algorithm python that search the list of tuples of divisors of an integer n

#### Exercise 84

write a python algorithm as a function which takes as argument an integer n and which returns the number of tuples (u, v, w) of integers such that u, v and w are all divisors of n and n = u + v + w. Example for n = 18 the list of sought tuples is: L = [(3, 6, 9), (3, 9, 6), (6, 3, 9), (6, 6, 6), (6, 9, 3), (9, 3, 6), ( 9, 6, 3)].

#### Solution

``````def numberOfTuples(n):
# Initializing the sought list
listTuples = []
for i in range(1,n+1):
for j in range(1,n+1):
for k in range(1,n+1):
if i + j + k == n  and n%i == 0 and n%j == 0 and n%k == 0:
listTuples.append((i , j , k))
return listTuples

# Testing algorithm
print("List of tuples searched for n = 18 is : " , numberOfTuples(18))
``````

Younes Derfoufi
my-courses.net

## Python Exercises With Solutions

1. Python Arithmetic Exercises
2. Equations & System Of Equations
3. Polynomials and Functions
4. Python Arithmetic Exercises
5. Numpy, Matplolib, Sympy , Scipy - Exercises
6. Python Arithmetic Exercises

Younes Derfoufi

## Sample Text 