from typing import List def tile(h: int, w: int, seq: List[int]) -> int: if h == 0 or w == 0: return 0 if h % seq[0] != 0 or w % seq[0] != 0: return -1 if len(seq) == 1: return (h // seq[0]) * (w // seq[0]) fit_h = h // seq[1] fit_w = w // seq[1] new_h = fit_h * seq[1] new_w = fit_w * seq[1] tile_smaller = tile(new_h, new_w, seq[1:]) return tile_smaller + (h * w - new_h * new_w) // (seq[0] * seq[0]) h, w = [int(x) for x in input().split(' ')] n = int(input()) sizes = [int(x) for x in input().split(' ')] print(tile(h, w, sizes))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | from typing import List def tile(h: int, w: int, seq: List[int]) -> int: if h == 0 or w == 0: return 0 if h % seq[0] != 0 or w % seq[0] != 0: return -1 if len(seq) == 1: return (h // seq[0]) * (w // seq[0]) fit_h = h // seq[1] fit_w = w // seq[1] new_h = fit_h * seq[1] new_w = fit_w * seq[1] tile_smaller = tile(new_h, new_w, seq[1:]) return tile_smaller + (h * w - new_h * new_w) // (seq[0] * seq[0]) h, w = [int(x) for x in input().split(' ')] n = int(input()) sizes = [int(x) for x in input().split(' ')] print(tile(h, w, sizes)) |