#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; template class Operators { public: template const T1 operator+(const T2& right) const{ T1 ans = static_cast( *this ); ans += right; return ans; } template const T1 operator-(const T2& right) const{ T1 ans = static_cast( *this ); ans -= right; return ans; } template const T1 operator*(const T2& right) const{ T1 ans = static_cast( *this ); ans *= right; return ans; } template const T1 operator/(const T2& right) const{ T1 ans = static_cast( *this ); ans /= right; return ans; } bool operator!=(const T1& right) const{ const T1& left = static_cast( *this ); return !(left == right); } bool operator>(const T1& right) const{ const T1& left = static_cast( *this ); return right < left; } bool operator<=(const T1& right) const{ const T1& left = static_cast( *this ); return !(right < left); } bool operator>=(const T1& right) const{ const T1& left = static_cast( *this ); return !(left < right); } }; class Fraction : public Operators { private: long long n; // 分子(numerator) long long d; // 分母(denominator) // 約分 void reduce(){ if(d < 0){ n *= -1; d *= -1; } long long a = abs(n); long long b = d; while(b != 0){ long long tmp = a % b; a = b; b = tmp; } n /= a; d /= a; } public: Fraction(){ n = 0; d = 1; } Fraction(long long n0){ n = n0; d = 1; } Fraction(long long n0, long long d0){ n = n0; d = d0; reduce(); } pair getValue() const{ return make_pair(n, d); } Fraction& operator+=(const Fraction& f){ n = n * f.d + d * f.n; d *= f.d; reduce(); return *this; } Fraction& operator-=(const Fraction& f){ n = n * f.d - d * f.n; d *= f.d; reduce(); return *this; } Fraction& operator*=(const Fraction& f){ n *= f.n; d *= f.d; reduce(); return *this; } Fraction& operator/=(const Fraction& f){ n *= f.d; d *= f.n; reduce(); return *this; } bool operator==(const Fraction& f) const{ return n == f.n && d == f.d; } bool operator<(const Fraction& f) const{ return n * f.d < f.n * d; } }; int main() { int n; cin >> n; vector a(n); for(int i=0; i> a[i]; int m; cin >> m; vector b(m); for(int i=0; i> b[i]; Fraction x = a[0]; for(int i=1; i=0; --i) y = Fraction(b[i]) / y; Fraction ans = x / y; cout << ans.getValue().first << ' ' << ans.getValue().second << endl; return 0; }