Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- int INF=2147483647;
- int inf=-2147483648;
- int mod=1000000007;
- #define read(x) cin >> x;
- #define fo(i,n) for(i=0;i<n;i++)
- #define one(x) cout<<(x)<<endl;
- #define two(a,b) cout<<(a)<<" "<<(b)<<endl;
- #define three(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl;
- #define four(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl;
- #define write(a,i) cout << a[i] << " ";
- map <int,bool> m;
- int main()
- {
- int a,b,c,d,kol=0;
- cin >> a >> b >> c >> d;
- while (1)
- {
- m[b]=1;b+=a;
- if (kol>100000) break;
- kol++;
- }
- kol=0;
- while (1)
- {
- if (m[d]==1)
- {
- cout << d;
- return 0;
- }
- d+=c;
- if (kol>100000)
- {
- cout << -1;
- return 0;
- }
- kol++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement