#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int>a,b;
signed main(){
int N;cin>>N;
char c='/';
while(N--){
int fz,fm;cin>>fz>>c>>fm;
a.push_back(fz);b.push_back(fm);
}
int temp_fz=0;int temp_fm=b[0];
for(int i=1;i<b.size();i++){
temp_fm= lcm(b[i],temp_fm);
}
for(int i=0;i<a.size();i++){
a[i]=a[i]*(temp_fm/b[i]);
temp_fz+=a[i];
}
int gys=gcd(temp_fm,temp_fz);
int now_fz=temp_fz/gys;
int now_fm=temp_fm/gys;
if(now_fm==1) cout<<now_fz;
else if(now_fz>now_fm) {cout<<now_fz/now_fm<<" "<<now_fz-(now_fz/now_fm)*now_fm<<"/"<<now_fm;}
else {cout<<now_fz<<"/"<<now_fm;}
}
L1-009 N个数求和 c++
最新推荐文章于 2024-06-17 22:13:25 发布
![](https://img-home.csdnimg.cn/images/20240611030827.png)