Example 1:Four metal rods of lengths 78 cm, 104 cm, 117 cm and 169 cm are to be cut into parts of equal length. Each part must be as long as possible. What is the maximum number of pieces that can be cut? Write a Python code to solve.

      
          import math
# Lengths of the metal rods in centimeters
lengths = [78, 104, 117, 169]

# Calculate the GCD of all lengths-pycent.com
gcd_of_lengths = math.gcd(math.gcd(math.gcd(lengths[0], lengths[1]), lengths[2]), lengths[3])

# Calculate the maximum number of pieces for each rod-pycent.com
pieces_per_rod = [length // gcd_of_lengths for length in lengths]

# Calculate the total maximum number of pieces that can be cut
total_pieces = sum(pieces_per_rod)
print("The solution for this question is solved by pycent.com")
print(gcd_of_lengths)
print(total_pieces)
#output:
The solution for this question is solved by pycent.com
13
36


          

Example 2:Three sets of English, Mathematics and Science books containing 336, 240 and 96 books respectively have to be stacked in such a way that all the books are stored subjectwise and the height of each stack is the same. Find the Total number of stacks that will be needed.

      
          import math
# Number of books for each subject
english_books = 336
math_books = 240
science_books = 96

# Calculate the GCD of the three numbers
gcd_value = math.gcd(math.gcd(english_books, math_books), science_books)

# Calculate the number of stacks for each subject
english_stacks = english_books // gcd_value
math_stacks = math_books // gcd_value
science_stacks = science_books // gcd_value

# Calculate the total number of stacks
total_stacks = english_stacks + math_stacks + science_stacks

print("The code created by pycent.com")
print("The GCD|HCF = ",gcd_value)
print("The Total number of stacks required = ", total_stacks)
#output
The code created by pycent.com
The GCD|HCF =  48
The Total number of stacks required =  14          

Example 3:The least number of square tiles required to pave the ceiling of a room 15 m 17 cm long and 9 m 2 cm broad is = ?

      
          import math

# Dimensions of the room in centimeters
length_cm = 1517  # 15 meters 17 centimeters
width_cm = 902    # 9 meters 2 centimeters

# Find the greatest common divisor of the length and width
tile_size_cm = math.gcd(length_cm, width_cm)

# Calculate the number of tiles required along each dimension
tiles_along_length = length_cm // tile_size_cm
tiles_along_width = width_cm // tile_size_cm

# Calculate the total number of square tiles required
total_tiles = tiles_along_length * tiles_along_width
print("Solution created by...pycent.com")
print("GCD found = ",tile_size_cm)
print("Tiles reqwuired = ",total_tiles)
#output:
Solution created by...pycent.com
GCD found =  41
Tiles reqwuired =  814          

Example 4:Nine chairs are numbered 1 to 9. Three women and four men wish to occupy one chair each. First the women chose the chairs from amongst the chair marked 1 to 5; and then the men select the chairs from amongst the remaining. The number of possible arrangements is , can you solve this

      
          import math

def combination(n, k):
    return math.factorial(n) // (math.factorial(k) * math.factorial(n - k))

def arrangements():
    # Women choosing and arranging chairs
    women_choose = combination(5, 3)  # C(5, 3)
    women_arrange = math.factorial(3)  # 3!
    total_women = women_choose * women_arrange
    
    # Men choosing and arranging chairs
    men_choose = combination(6, 4)  # C(6, 4) (since 6 chairs are left after women choose)
    men_arrange = math.factorial(4)  # 4!
    total_men = men_choose * men_arrange
    
    # Total arrangements
    total_arrangements = total_women * total_men
    return total_arrangements

# Calculate the total number of arrangements
print(arrangements())