#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
long long h,w,n,b;
std::vector<long long>obr;
std::vector<long long>x,y;
int main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(NULL);
std::cin>>h>>w>>n;
x.resize(n);
y.resize(n);
for(int i=0;i<n;i++){
std::cin>>b;
obr.emplace_back(b);
}
for(int i=n-1;i>=0;i--){
x[i]=h/obr[i];
h%=obr[i];
y[i]=w/obr[i];
w%=obr[i];
}
if(h+w!=0){
std::cout<<-1<<std::endl;
return 0;
}
long long result=0;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++){
result+=(j>i?obr[j]/obr[i]:obr[i]/obr[j])*x[i]*y[j];
}
std::cout<<result<<std::endl;
}
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 | #include <iostream> #include <vector> #include <set> #include <algorithm> long long h,w,n,b; std::vector<long long>obr; std::vector<long long>x,y; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(NULL); std::cin>>h>>w>>n; x.resize(n); y.resize(n); for(int i=0;i<n;i++){ std::cin>>b; obr.emplace_back(b); } for(int i=n-1;i>=0;i--){ x[i]=h/obr[i]; h%=obr[i]; y[i]=w/obr[i]; w%=obr[i]; } if(h+w!=0){ std::cout<<-1<<std::endl; return 0; } long long result=0; for(int i=0;i<n;i++) for(int j=0;j<n;j++){ result+=(j>i?obr[j]/obr[i]:obr[i]/obr[j])*x[i]*y[j]; } std::cout<<result<<std::endl; } |
English