比赛 |
202110省实验桐柏一中普及组联赛 |
评测结果 |
AAAWAAAWWW |
题目名称 |
分数运算 |
最终得分 |
60 |
用户昵称 |
nichengyan |
运行时间 |
0.000 s |
代码语言 |
C++ |
内存使用 |
0.00 MiB |
提交时间 |
2021-10-18 19:16:11 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
int n,m;
ull gcd(int a,int b){
if(a%b==0) return b;
return gcd(b,a%b);
}
ull up=-1,down=-1;
void huajian(){
if(up==down){
up=1;
down=1;
}else if(up<down){
ull tmp=up;
up=up/gcd(down,up);
down=down/gcd(down,tmp);
}else{
ull tmp=up;
up=up/gcd(tmp,down);
down=down/gcd(tmp,down);
}
}
int main(){
freopen("fenshu.in","r",stdin);
freopen("fenshu.out","w",stdout);
cin>>n>>m;
for(int i=1;i<=n;i++){
ull a,b;
cin>>a>>b;
if(up==-1&&down==-1){
up=a,down=b;
}else{
up=up*b+down*a;
down=down*b;
}
huajian();
}
for(int i=1;i<=m;i++){
ull a;
cin>>a;
down*=a;
huajian();
}
if(down==1){
cout<<up;
}else{
cout<<up<<" "<<down;
}
fclose(stdin);
fclose(stdout);
return 0;
}