h, w = map(int, input().split()) n = int(input()) obrazy = list(map(int, input().split())) def solve(w, h): if w == 0 or h == 0: return 0 for i in reversed(obrazy): if i <= w and i <= h: a, b = divmod(w, i) c, d = divmod(h, i) return solve(b, h) + solve(i, d) * a + a * c else: raise "NUH UH" try: print(solve(w, h)) except: print(-1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | h, w = map(int, input().split()) n = int(input()) obrazy = list(map(int, input().split())) def solve(w, h): if w == 0 or h == 0: return 0 for i in reversed(obrazy): if i <= w and i <= h: a, b = divmod(w, i) c, d = divmod(h, i) return solve(b, h) + solve(i, d) * a + a * c else: raise "NUH UH" try: print(solve(w, h)) except: print(-1) |