#include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); long long n,h,w,zh,zw,wyn; vector<long long>d; cin>>h>>w; cin>>n; for(int i=0;i<n;++i){ cin>>zh; d.emplace_back(zh); } if(h%d[0]||w%d[0]){cout<<-1;return 0;} wyn=(h/d.back())*(w/d.back()); zh=h%d.back();zw=w%d.back(); d.pop_back(); while(d.size()){ wyn+=((h-zh)/d.back())*(zw/d.back()); wyn+=(zh/d.back())*((w-zw)/d.back()); wyn+=(zh/d.back())*(zw/d.back()); zh=zh%d.back();zw=zw%d.back(); d.pop_back(); } cout<<wyn; }
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 | #include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); long long n,h,w,zh,zw,wyn; vector<long long>d; cin>>h>>w; cin>>n; for(int i=0;i<n;++i){ cin>>zh; d.emplace_back(zh); } if(h%d[0]||w%d[0]){cout<<-1;return 0;} wyn=(h/d.back())*(w/d.back()); zh=h%d.back();zw=w%d.back(); d.pop_back(); while(d.size()){ wyn+=((h-zh)/d.back())*(zw/d.back()); wyn+=(zh/d.back())*((w-zw)/d.back()); wyn+=(zh/d.back())*(zw/d.back()); zh=zh%d.back();zw=zw%d.back(); d.pop_back(); } cout<<wyn; } |