Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: anonymous
Problemset: Fraction
Language: cpp
Time: 0.004 second
Submitted On: 2026-11-07 20:34:14
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll x,ll y){
if(x < 0) x = -x;
if(y < 0) y = -y;
while(y){
ll t =x%y;
x = y;
y = t;
}
return x;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll a,b; cin >> a >> b;
int n; cin >> n;
while(n--){
char op; cin >> op;
ll p,q; cin >> p >> q;
if (op == '-') a*=q, p*=b ,b*=q ,a-=p;
else if (op == '+') a*=q, p*=b ,b*=q ,a+=p;
else if (op == '*') a*=p ,b*=q;
else if (op == '/') a*=q ,b*=p;
ll g = gcd(a,b);
a /= g, b/= g;
if(b < 0){
a = -a;
b = -b;
}
if(a != 0)cout << a << ' ' << b << '\n';
else cout << "0 1" << '\n';
}
}