Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(){
- int a, b, c, d, s1 = 0, s2 = 0;
- cin>>a>>b>>c>>d;
- for(int n = 1;n < 10;n++)
- {
- s1 = b+(2*a+(n-1)*a)*n/2;
- s2 = d+(2*c+(n-1)*c)*n/2;
- if(s1 == s2){
- cout<<s1;
- return 0;
- }
- }
- cout<<-1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement