比赛 202110省实验桐柏一中普及组联赛 评测结果 AAAAAAAAAW
题目名称 分数运算 最终得分 90
用户昵称 tb_hzm 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2021-10-18 19:18:32
显示代码纯文本
#include <cstdio>

using namespace std;

typedef unsigned long long ull;

int n, m;

ull gcd(ull num1, ull num2) {
	if(num2 == 0)
		return num1;
	return gcd(num2, num1 % num2);
}

ull fr1, fr2, sm1, sm2 = 1;

ull itrg;

int main() {
	freopen("fenshu.in", "r", stdin);
	freopen("fenshu.out", "w", stdout);
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++) {
		scanf("%llu %llu", &fr1, &fr2);
		sm1 = sm1 * fr2 + sm2 * fr1;
		sm2 *= fr2;
		int tmp = gcd(sm1, sm2);
		sm1 /= tmp;
		sm2 /= tmp;
	}
	for(int i = 1; i <= m; i++) {
		scanf("%llu", &itrg);
		sm2 *= itrg;
		int tmp = gcd(sm1, sm2);
		sm1 /= tmp;
		sm2 /= tmp;
	}
	int tmp = gcd(sm1, sm2);
	sm1 /= tmp;
	sm2 /= tmp;
	if(sm2 == 1)
		printf("%llu", sm1);
	else
		printf("%llu %llu", sm1, sm2);
	return 0;
}