比赛 |
202110省实验桐柏一中普及组联赛 |
评测结果 |
AAAAAAAAAA |
题目名称 |
分数运算 |
最终得分 |
100 |
用户昵称 |
HeSn |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2021-10-18 19:41:02 |
显示代码纯文本
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define LL __int128
LL a, b;
LL read() {
LL x = 0;
string c;
cin >> c;
for(int i = 0; i < c.length(); i ++) {
x *= 10;
x += c[i] - '0';
}
return x;
}
LL gcd(LL x, LL y) {
while(x > 0 && y > 0)
{
LL t = x % y;
x = y;
y = t;
}
return x;
}
LL lcm(LL x, LL y) {
return x / gcd(x, y) * y;
}
int print(LL x) {
if(x > 9) {
print(x / 10);
int y = x % 10;
cout << y;
}
else {
int y = x % 10;
cout << y;
}
}
int n, m, fz[200], fm[100];
int main() {
freopen("fenshu.in", "r", stdin);
freopen("fenshu.out", "w", stdout);
cin >> n >> m;
LL p = 1, q = 0;
for(int i = 1; i <= n; i ++) {
cin >> fz[i] >> fm[i];
}
for(int i = 1; i <= n; i ++) {
LL l = lcm(p, fm[i]);
q = q * (l / p);
q = q + (l / fm[i]) * fz[i];
p = l;
LL t = gcd(p, q);
p /= t;
q /= t;
}
for(int i = 1; i <= m; i ++) {
int x;
cin >> x;
p *= x;
}
LL t = gcd(p, q);
p /= t;
q /= t;
if(p == 1) {
print(q);
return 0;
}
print(q);
cout << ' ';
print(p);
}