#include <bits/stdc++.h>
#define int long long
using namespace std;
int h,w,n;
stack <int> wej;
int wynik;
signed main(){
cin >> h >> w >> n;
int a;
cin >> a;
if(h%a != 0 || w%a != 0){
cout << "-1";
return 0;
}
h /= a;
w /= a;
wej.push(1);
for(int i = 1;i < n;i++){
int b;
cin >> b;
wej.push(b/a);
}
int x = h,y = w;
while(!wej.empty()){
int d = wej.top();
wej.pop();
wynik += (x/d) * (w/d) + (y/d) * (h/d) - (x/d) * (y/d);
x %= d;
y %= d;
}
cout << wynik;
return 0;
}
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 | #include <bits/stdc++.h> #define int long long using namespace std; int h,w,n; stack <int> wej; int wynik; signed main(){ cin >> h >> w >> n; int a; cin >> a; if(h%a != 0 || w%a != 0){ cout << "-1"; return 0; } h /= a; w /= a; wej.push(1); for(int i = 1;i < n;i++){ int b; cin >> b; wej.push(b/a); } int x = h,y = w; while(!wej.empty()){ int d = wej.top(); wej.pop(); wynik += (x/d) * (w/d) + (y/d) * (h/d) - (x/d) * (y/d); x %= d; y %= d; } cout << wynik; return 0; } |
English