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

using namespace std;

int main() {
    long long h, w;
    int n;
    cin >> h >> w >> n;
    vector<long long> size(n);
    for (int i = 0; i < n; i++) {
        cin >> size[i];
    }

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

    long long total_square = 0;
    long long covered_area = 0; 
    long long current_area = h * w; 

    for (int i = n - 1; i >= 0 && current_area > 0; i--) {
        long long square = size[i] * size[i];
        long long needed_squares = current_area / square;
        current_area -= needed_squares * square;
        total_square += needed_squares;
    }

    cout << total_square << endl;

    return 0;
}