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
#include <iostream>
#include <vector>

using namespace std;

#define ll long long

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    ll height, width, number_of_pictures, result = 0; cin >> height >> width >> number_of_pictures;

    vector<ll> pictures_sizes(number_of_pictures);

    for(int i = 0; i < number_of_pictures; i ++){
        cin >> pictures_sizes[i];

        if(i == 0){
            if(height % pictures_sizes[i] != 0 || width % pictures_sizes[i] != 0){
                cout << "-1";
                return 0;
            } else {
                result += (height / pictures_sizes[i]) * (width / pictures_sizes[i]);;
            }
        } else {
            height = height - height % pictures_sizes[i];
            width = width - width % pictures_sizes[i];

            result = result - (height / pictures_sizes[i - 1]) * (width / pictures_sizes[i - 1]) + (height / pictures_sizes[i]) * (width / pictures_sizes[i]);
        }
    }

    cout << result << '\n';

    return 0;
}