#include <bits/stdc++.h>
using namespace std;
int A[31], n, a, b;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>a>>b>>n;
A[0]=1000000001;
for(int i=n; i>0; --i){
cin>>A[i];
}
if(a%A[n]!=0 || b%A[n]!=0){
cout<<"-1";
return 0;
}
int i=1;
long long x, y, c, d, t=0;
while( i<n+1 ){
x=a%A[i-1];
y=b%A[i-1];
x=x/A[i];
y=y/A[i];
c=a/A[i];
d=b/A[i];
t += c*y + d*x - x*y;
++i;
}
cout<<t;
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 | #include <bits/stdc++.h> using namespace std; int A[31], n, a, b; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>a>>b>>n; A[0]=1000000001; for(int i=n; i>0; --i){ cin>>A[i]; } if(a%A[n]!=0 || b%A[n]!=0){ cout<<"-1"; return 0; } int i=1; long long x, y, c, d, t=0; while( i<n+1 ){ x=a%A[i-1]; y=b%A[i-1]; x=x/A[i]; y=y/A[i]; c=a/A[i]; d=b/A[i]; t += c*y + d*x - x*y; ++i; } cout<<t; return 0; } |
English