Advertisement
TimxAG

Untitled

Mar 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int INF=2147483647;
  5. int inf=-2147483648;
  6. int mod=1000000007;
  7. #define read(x) cin >> x;
  8. #define fo(i,n) for(i=0;i<n;i++)
  9. #define one(x) cout<<(x)<<endl;
  10. #define two(a,b) cout<<(a)<<" "<<(b)<<endl;
  11. #define three(a,b,c) cout<<(a)<<" "<<(b)<<" "<<(c)<<endl;
  12. #define four(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl;
  13. #define write(a,i) cout << a[i] << " ";
  14. map <int,bool> m;
  15. int main()
  16. {
  17. int a,b,c,d,kol=0;
  18. cin >> a >> b >> c >> d;
  19. while (1)
  20. {
  21. m[b]=1;b+=a;
  22. if (kol>100000) break;
  23. kol++;
  24. }
  25. kol=0;
  26. while (1)
  27. {
  28. if (m[d]==1)
  29. {
  30. cout << d;
  31. return 0;
  32. }
  33. d+=c;
  34. if (kol>100000)
  35. {
  36. cout << -1;
  37. return 0;
  38. }
  39. kol++;
  40. }
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement