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

#include <iostream>
#include <fstream>
#include <vector>
#include <utility>

using namespace std;

typedef unsigned long long ull;

int _n;
int _m; 
vector<pair<ull, ull> > _fra;
vector<ull> _num;
ull _sonRes;
ull _momRes;

void ParseIn () {
	
	ull son;
	ull mom;
	ull cur;
	
	ifstream inFile("fenshu.in");
	
	inFile >> _n >> _m;
	for (int i = 1; i <= _n; i++) {
		inFile >> son >> mom;
		_fra.push_back(make_pair(son, mom));
	}
	for (int i = 1; i <= _m; i++) {
		inFile >> cur;
		_num.push_back(cur);
	}
	
	inFile.close();
	
}

ull calGcd (ull one, ull two) {
	if (one % two == 0) {
		return two;
	}
	else {
		return calGcd (two, one % two);
	}
}

void beEasy () {
	int gcd = calGcd (_sonRes, _momRes);
	
	_sonRes /= gcd;
	_momRes /= gcd;
}

void plusFra () {
	_sonRes = _fra[0].first;
	_momRes = _fra[0].second; 
	for (int i = 1; i < _fra.size(); i++) {
		ull son = _fra[i].first;
		ull mom = _fra[i].second;
		
		ull lcm = mom * _momRes / calGcd (mom, _momRes);
		
		_sonRes = _sonRes * lcm / _momRes + son * lcm / mom;
		_momRes = lcm;
		
		beEasy ();
	}
}

void multNum () {
	for (int i = 0; i < _num.size(); i++) {
		_momRes *= _num[i];
		
		beEasy ();
	}
}

void Core () {
	
	plusFra ();
	multNum ();
	
}

void CWriteOut () {
	
	ofstream outFile("fenshu.out");
	
	outFile << _sonRes;
	if (_momRes != 1) {
		outFile << ' ' << _momRes;
	}
	outFile << endl;
	
	outFile.close();
	
}

int main () {
	
	ParseIn ();
	Core ();
	CWriteOut ();
	
	return 0;
}