L1-009. N个数求和
来源:互联网 发布:淘宝天猫内部券公众号 编辑:程序博客网 时间:2024/06/05 22:16
#include<iostream>#include<cstdio>using namespace std;//数学//扩展欧几里得求最小公倍数最大公约数typedef long long ll;void gcd(ll a,ll b,ll& d,ll&x,ll&y){ if(!b) d=a,x=1,y=0; else{ gcd(b,a%b,d,y,x); y-=x*(a/b); return; }} int main(){ ll d,x,y,a=0,b=1,a1,b1,N; cin>>N; for(int i=0;i<N;i++){ scanf("%lld/%lld",&a1,&b1); if(a1==0)continue; gcd(b,b1,d,x,y); ll lcp=b/d*b1; a=a*lcp/b+a1*lcp/b1; b=lcp; gcd(a,b,d,x,y); a/=d,b/=d; } if(a/b!=0&&a%b!=0){ printf("%lld %lld/%lld",a/b,a%b,b); } else if(a%b==0){ cout<<a/b<<endl; } else{ cout<<a<<"/"<<b<<endl; } return 0;}
0 0
- L1-009. N个数求和
- L1-009. N个数求和
- L1-009. N个数求和
- L1-009. N个数求和
- L1-009. N个数求和
- L1-009. N个数求和
- L1-009. N个数求和
- L1-009. N个数求和
- L1-009. N个数求和
- L1-009. N个数求和
- L1-009. N个数求和
- L1-009. N个数求和
- L1-009. N个数求和
- L1-009. N个数求和
- L1-009. N个数求和
- L1-009. N个数求和
- L1-009. N个数求和
- L1-009. N个数求和
- Bzoj 1926: [Sdoi2010]粟粟的书架(二分答案+乱搞+主席树)
- form表单数据转成json数据的方法
- Angular4.0.0正式发布,附新特性及升级指南
- 常见的消息映射格式总结
- 网络模型可视化的方法
- L1-009. N个数求和
- PAT L1-020. 帅到没朋友 集合set瞎搞
- 快速排序的简单实现
- 完全背包(经典dp)
- zxing方式生成二维码
- JSP入门:介绍什么是JSP和Servlet
- javacef
- M1卡破解(自从学校升级系统之后,还准备在研究下)
- 常见问题及要注意的知识点