h, w = map(int, input().split()) n = int(input()) ds = reversed(list(map(int, input().split()))) result = 0 area = 0 for d in ds: h1 = h // d * d w1 = w // d * d area1 = h1 * w1 result += (area1 - area) // d**2 area = area1 if area == h * w: print(result) else: print(-1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | h, w = map(int, input().split()) n = int(input()) ds = reversed(list(map(int, input().split()))) result = 0 area = 0 for d in ds: h1 = h // d * d w1 = w // d * d area1 = h1 * w1 result += (area1 - area) // d**2 area = area1 if area == h * w: print(result) else: print(-1) |