#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int main(){ vector r,m; rep(i,2){ long long b,c; cin>>b>>c; c += b * 10000; c %= b; m.push_back(b); r.push_back(c); } auto ans = crt(r,m); if(ans.second==0)cout<<"NaN"<