Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include <iostream>
- #include <vector>
- #include <string>
- #include <algorithm>
- using namespace std;
- typedef long long lint;
- const int N=100*1000;
- lint n;
- lint a, b, c, d;
- lint mas[110];
- bool r=false;
- int main() {
- cin>>a>>b>>c>>d;
- if(b<d) {
- swap(a, c);
- swap(b, d);
- }
- for(n=0; n<=max(b, d)+c; n++) {
- if((b%c+(a%c)*(n%c))%c==d%c ) {
- r=true;
- break;
- }
- //if(mas[n%c]==0) mas[n%c]++;
- //else break;
- }
- if(r) cout<<b+a*n<<endl;
- else cout<<-1<<endl;
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement