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
31
32
33
#include <bits/stdc++.h>
#define ll long long

int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(NULL);
  ll h, w;
  std::cin >> h >> w;
  int n;
  std::cin >> n;
  std::vector<ll> d(n, 0);
  for (auto &x : d)
    std::cin >> x;

  if ((h % d[0]) != 0 || (w % d[0]) != 0) {
    std::cout << "-1\n";
    return 0;
  }

  ll res = 0;
  ll A = 0;
  std::reverse(d.begin(), d.end());

  for (auto &x : d) {
    ll hh = (h / x) * x;
    ll ww = (w / x) * x;
    ll B = hh * ww;
    res += (B - A) / (x * x);
    A = B;
  }

  std::cout << res << "\n";
}