#include <bits/stdc++.h> #define ll long long using namespace std; int main(){ ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); ll h, w, n, answer; cin>>h>>w>>n; //--------------------- ll d; cin>>d; if(h % d != 0 || w % d != 0){cout<<"-1"; return 0;} answer = (h/d) * (w/d); //--------------------- n--; while(n--){ ll now; cin>>now; ll now_teil = ((ll)(h/now)) * ((ll)(w/now)); answer -= ((now/d) * (now/d) - 1) * now_teil; h -= h % now; w -= w % now; d = now; } //--------------------- cout<<answer; 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 | #include <bits/stdc++.h> #define ll long long using namespace std; int main(){ ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0); ll h, w, n, answer; cin>>h>>w>>n; //--------------------- ll d; cin>>d; if(h % d != 0 || w % d != 0){cout<<"-1"; return 0;} answer = (h/d) * (w/d); //--------------------- n--; while(n--){ ll now; cin>>now; ll now_teil = ((ll)(h/now)) * ((ll)(w/now)); answer -= ((now/d) * (now/d) - 1) * now_teil; h -= h % now; w -= w % now; d = now; } //--------------------- cout<<answer; return 0; } |