fork download
  1. def calculate_area(n, k, l):
  2. """Calculates the area of the union of squares.
  3.  
  4. Args:
  5. n: The number of squares.
  6. k: The length of the side of each square.
  7. l: The spacing between the squares.
  8.  
  9. Returns:
  10. The area of the union of squares.
  11. """
  12.  
  13. total_area = 0
  14. for i in range(n):
  15. # Calculate the coordinates of the bottom-left corner of the square
  16. x = i * (k + l)
  17. y = i * (k + l)
  18.  
  19. # Calculate the area of the square
  20. square_area = k * k
  21.  
  22. # Add the area of the square to the total area
  23. total_area += square_area
  24.  
  25. return total_area
  26.  
  27. # Get the input from the user
  28. n, k, l = map(int, input().split())
  29.  
  30. # Calculate the area of the union of squares
  31. area = calculate_area(n, k, l)
  32.  
  33. # Print the output
  34. print(area)
Success #stdin #stdout 0.03s 9796KB
stdin
4 1 2
stdout
4