#include<bits/stdc++.h> #define LL long long #define LLL __int128 #define uint unsigned #define ldb long double #define uLL unsigned long long using namespace std; int H,W,n,D[35];LL ans; signed main(){ cin.tie(0)->sync_with_stdio(0); cin>>H>>W>>n,D[n]=max(H,W)+1; for(int i=0;i<n;++i)cin>>D[i]; if(H%D[0]||W%D[0])return cout<<"-1",0; for(int i=0;i<n;++i)ans+=1ll*(H/D[i])*(W/D[i])-1ll*(H/D[i+1]*(D[i+1]/D[i]))*(W/D[i+1]*(D[i+1]/D[i])); return cout<<ans,0; } /* */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include<bits/stdc++.h> #define LL long long #define LLL __int128 #define uint unsigned #define ldb long double #define uLL unsigned long long using namespace std; int H,W,n,D[35];LL ans; signed main(){ cin.tie(0)->sync_with_stdio(0); cin>>H>>W>>n,D[n]=max(H,W)+1; for(int i=0;i<n;++i)cin>>D[i]; if(H%D[0]||W%D[0])return cout<<"-1",0; for(int i=0;i<n;++i)ans+=1ll*(H/D[i])*(W/D[i])-1ll*(H/D[i+1]*(D[i+1]/D[i]))*(W/D[i+1]*(D[i+1]/D[i])); return cout<<ans,0; } /* */ |