AC代码

null him 2021-01-17 19:27:54 10
#include<iostream>
#include<cstdio>
using namespace std;
long long int f1(long long int n,long long int c){
	if(n%c==0){
		return c;
	}
	else{
		return f1(c,n%c);
	}
}
long long int f(long long int x,long long int y){
	if(x>=y){
		for(int i=1;;i++){
			if(x*i%y==0){
				return x*i;
			}
		}
	}
	for(int i=1;;i++){
		if(y*i%x==0){
			return i*y;
		}
	}
}
struct fs{
	int fm,fz;
}a[25];
int main(){
	long long int n,ans=1,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		scanf("%d/%d",&a[i].fz,&a[i].fm);
	}
	for(int i=1;i<=n;i++){
		ans=f(ans,a[i].fm);
	}
	for(int i=1;i<=n;i++){
		sum+=a[i].fz*ans/a[i].fm;
	}
	if(sum%ans==0){
		printf("%d",sum/ans);
	}
	else{
		printf("%d/%d",sum/f1(ans,sum),ans/f1(ans,sum));
	}
	return 0;
}
{{ vote && vote.total.up }}

共 6 条回复

zhengchenhao1

百分百错

null him

???

root 站长

出数据啊。

null him

@liuser2

null him

看来得来一道加强版了

null him

确实是长了亿点