比赛 |
202110省实验桐柏一中普及组联赛 |
评测结果 |
AAAAAAAAAA |
题目名称 |
分数运算 |
最终得分 |
100 |
用户昵称 |
yrtiop |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2021-10-18 19:42:59 |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <algorithm>
#define INT __int128
using namespace std;
INT TAT;
INT gcd(INT x,INT y) {
return !y ? x : gcd(y , x % y);
}
INT read() {
INT s = 0;
char c = getchar();
while(c < '0'||c > '9')c = getchar();
while(c >= '0'&&c <= '9')s = (s << 1) + (s << 3) + (c ^ '0'),c = getchar();
return s;
}
void write(INT x) {
if(x > 9)write(x / 10);
putchar(x % 10 + '0');
return ;
}
struct query {
INT p,q;
query() {
p = 0;
q = 1;
}
query(INT p,INT q):p(p),q(q){}
void readin() {
p = read();
q = read();
return ;
}
query operator + (query x)const {
INT t = gcd(q , x.q);
INT QAQ = (p * (x.q / t)) + (x.p * (q / t));
INT qwq = q * x.q / t;
t = gcd(QAQ , qwq);
return query(QAQ / t , qwq / t);
}
query operator * (INT x)const {
INT t = gcd(p , x);
return query(p / t , q * (x / t));
}
}now,cur;
int n,m;
int main() {
freopen("fenshu.in","r",stdin);
freopen("fenshu.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i = 1;i <= n;++ i) {
cur.readin();
now = now + cur;
}
for(int i = 1;i <= m;++ i) {
TAT = read();
now = now * TAT;
}
INT p = now.p,q = now.q;
if(q > p) {
write(p);
putchar(' ');
write(q);
}
else if(p > q&&(p % q)) {
write(p);
putchar(' ');
write(q);
}
else if(p >= q&&!(p % q)) {
write(p / q);
}
fclose(stdin);
fclose(stdout);
return 0;
}