比赛 202110省实验桐柏一中普及组联赛 评测结果 AAAAAAAAAW
题目名称 分数运算 最终得分 90
用户昵称 暗月 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2021-10-18 18:15:10
显示代码纯文本
#include<iostream>
using namespace std;
long long n, m, na = 0, nb = 1;
long long aaa(long long a, long long b) {
	if (a % b == 0)
		return b;
	else
		return aaa(b, a % b);
}
int main() {
	freopen("fenshu.in", "r", stdin);
	freopen("fenshu.out", "w", stdout);
	cin >> n >> m;
	for (int i = 1; i <= n; i ++) {
		long long x, y;
		cin >> x >> y;
		na = na * y + nb * x;
		nb = y * nb;
		long long t = aaa(na, nb);
		na /= t, nb /= t;
//		cout << na << " " << nb << "\n";
	}
	for (int i = 1; i <= m; i ++) {
		long long x;
		cin >> x;
		nb *= x;
		long long t = aaa(na, nb);
		na /= t, nb /= t;
	}
	if (na % nb == 0)
		cout << na / nb;
	else
		cout << na << " " << nb;
	return 0;
}