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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <unordered_map>
#include <string>
#include <queue>
#include <deque>
#include <set>
#include <cstdlib>
#include <ctime>
#include<chrono>
#include<thread>
#include<iomanip>
#include<fstream>
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

using namespace std;


int main()
{
    ll h, w;
    cin >> h >> w;
    ll n;
    cin >> n;
    vector<ll> arr(n);
    for(ll i = 0; i < n; i++) {
        cin >> arr[i];
    }
    if(h % arr[0] != 0 || w % arr[0] != 0) {
        cout << -1 << endl;
    }
    else {
        ll ans = 0;
        for(int i = 0; i < n; i++) {
            if(i > 0) {
                ll dependence = arr[i] / arr[i - 1];
                dependence *= dependence;
                dependence--;
                ans -= dependence * (h / arr[i]) * (w / arr[i]);
                
            }
            else if(i == 0) ans += (h / arr[i]) * (w / arr[i]);
        }
        cout << ans << endl;
    }
    return 0;
}