codeforces #406 A. The Monster

方針

法則性とか考えないで総当りでいけるっぽい

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int ans = -1;
    for(int i=0;i<1000;i++) {
        bool flag = false;
        for(int j=0;j<1000;j++) {
            if(b+a*i == d+c*j) {
                ans = b + a * i;
                flag = true;
                break;
            }
        }
        if(flag) break;
    }

    cout << ans << endl;
}