比赛 |
202110省实验桐柏一中普及组联赛 |
评测结果 |
AAAAAAAAAW |
题目名称 |
分数运算 |
最终得分 |
90 |
用户昵称 |
ming_xin |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2021-10-18 19:18:14 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
unsigned long long pd = 0;
unsigned long long fenmu,fenzi;
unsigned long long zheng;
unsigned long long ans = 0,ans2 = 0;
unsigned long long gcd(unsigned long long a,unsigned long long b)
{
if(a<b)swap(a,b);
if(a%b==0)return b;
else gcd(b,a%b);
}
unsigned long long lcm(unsigned long long a, unsigned long long b)
{
return a*b/gcd(a,b);
}
inline int read()
{
register int s=0,w=1;
register char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')
{
w=-1;
ch=getchar();
}
}
while(ch>='0'&&ch<='9')
{
s=s*10+ch-'0';
ch=getchar();
}
return s*w;
}
int main(void)
{
freopen("fenshu.in","r",stdin);
freopen("fenshu.out","w",stdout);
int n,m;
n = read(); m = read();
for(int i = 0; i < n; ++i)
{
fenzi = read(); fenmu = read();
if(ans == 0 || ans2 == 0)
{
ans = fenzi; ans2 = fenmu;
continue;
}
unsigned long long c = lcm(ans2,fenmu);
ans = ans*(c/ans2) + fenzi*(c/fenmu);
ans2 = c;
unsigned long long d = gcd(ans, ans2);
ans /= d; ans2 /= d;
//printf("jieguo:%lld %lld\n", ans, ans2);
}
for(int i = 0; i < m; ++i)
{
zheng = read();
ans2 *= zheng;
//printf("jieguo2:%lld %lld\n", ans, ans2);
}
unsigned long long d = gcd(ans, ans2);
if(ans % ans2 == 0) printf("%lld", ans/ans2);
else printf("%lld %lld", ans/d, ans2/d);
return 0;
}