Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long int
- int main()
- {
- ll a,b,c,d;
- cin>>a>>b>>c>>d;
- if(b==d)
- {
- cout<<b<<endl;
- return 0;
- }
- ll ara[10000],ara2[10000];
- ll i=0;
- bool flag=false;
- bool flag2=false;
- if(b%2==0)ara[i]=1;
- else ara[i]=0;
- i++;
- ll j=0;
- if(d%2==0)ara2[j]=1;
- else ara2[j]=0;
- j++;
- while(1)
- {
- if(b<d)
- {
- b+=a;
- //a+=a;
- if(b%2==0)ara[i]=1;
- else ara[i]=0;
- if(ara[i]!=ara[i-1])flag=true;
- i++;
- }
- else
- {
- d+=c;
- //c+=c;
- if(d%2==0)ara2[j]=1;
- else ara2[j]=0;
- if(ara2[j]!=ara2[j-1])flag2=true;
- j++;
- }
- if(b==d)
- {
- cout<<b<<endl;
- break;
- }
- if(i>10&&j>10)
- {
- if(flag==false&&flag2==false&&ara[0]!=ara2[0])
- {
- cout<<"-1"<<endl;
- return 0;
- }
- else continue;
- }
- //cout<<b<<" "<<d<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement