1638: Continued Fraction

Time Limit: 1 Sec  Memory Limit: 128 MB

Description

Input

Output

Sample Input

4 3
5 1 1 2
5 2 2

Sample Output

11
0 5
30 4 6
1 27

HINT

 

Source

解题:主要任务是把任一一个分数化成连分式。
 
方法就是分子分母同时不断的除以分子,直到分子为0。
 
至于加,减,乘,除都是先算出分数,然后把分数化成连分数。。
 
 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n,m,a1[],a2[];
LL gcd(LL x,LL y){
return y?gcd(y,x%y):x;
}
void dfs(LL &A,LL &B,int *arr,int cur,int dep){
if(cur == dep-){
A = arr[cur];
B = ;
}
if(cur >= dep-) return;
LL tmpA,tmpB;
dfs(tmpA,tmpB,arr,cur+,dep);
LL theGCD = gcd(A = arr[cur]*tmpA + tmpB,B = tmpA);
A /= theGCD;
B /= theGCD;
}
void print(LL x,LL y){
LL GCD = gcd(x,y);
LL tmp = (x /= GCD)/(y /= GCD),p = x - tmp*y;
printf("%lld%c",tmp,p?' ':'\n');
if(p) print(y,p);
}
int main(){
while(~scanf("%d %d",&n,&m)){
for(int i = ; i < n; ++i) scanf("%d",a1+i);
for(int i = ; i < m; ++i) scanf("%d",a2+i);
LL A1 = ,B1 = ,A2 = ,B2 = ;
dfs(B1,A1,a1,,n);
dfs(B2,A2,a2,,m);
A1 += a1[]*B1;
A2 += a2[]*B2;
print(A1*B2 + A2*B1,B1*B2);
print(A1*B2 - A2*B1,B1*B2);
print(A1*A2,B1*B2);
print(A1*B2,A2*B1);
}
return ;
}

CSUOJ 1638 Continued Fraction的更多相关文章

  1. HDU - 3556 - Continued Fraction

    先上题目: Continued Fraction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Jav ...

  2. Continued Fractions CodeForces - 305B (java+高精 / 数学)

    A continued fraction of height n is a fraction of form . You are given two rational numbers, one is ...

  3. CF 305B——Continued Fractions——————【数学技巧】

    B. Continued Fractions time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  4. 2014-2015 ACM-ICPC East Central North America Regional Contest (ECNA 2014) A、Continued Fractions 【模拟连分数】

    任意门:http://codeforces.com/gym/100641/attachments Con + tin/(ued + Frac/tions) Time Limit: 3000/1000 ...

  5. 欧拉工程第65题:Convergents of e

    题目链接 现在做这个题目真是千万只草泥马在心中路过 这个与上面一题差不多 这个题目是求e的第100个分数表达式中分子的各位数之和 What is most surprising is that the ...

  6. BCTF warmup 50

    这是一道关于RSA的解密题:首先,我们要明白,通常是公钥加密.私钥解密,私钥签名.公钥验证.这个题目中给出的是一个公钥和一段密文. 刚开始一直以为和验证签名有关,费劲脑汁也想不出来怎么办.下面介绍些思 ...

  7. (Problem 57)Square root convergents

    It is possible to show that the square root of two can be expressed as an infinite continued fractio ...

  8. C++开源库集合

    | Main | Site Index | Download | mimetic A free/GPL C++ MIME Library mimetic is a free/GPL Email lib ...

  9. Exercises for IN1900

    Exercises for IN1900October 14, 2019PrefaceThis document contains a number of programming exercises ...

随机推荐

  1. 6、Java类、对象、构造器、引用类型内存基本知识、引用类型值传递

    1.面向对象三大特征: 封装:encapsulation 继承:inheritance 多态:polymorphism 2.类中 数据特征(property):属性(attribute)静态的stat ...

  2. Ryu基本操作的REST API调用演示样例

    import urllib2 import json def get_all_switches(): url = "http://127.0.0.1:8080/v1.0/topology/s ...

  3. MDNS DDoS 反射放大攻击——攻击者假冒被攻击者IP向网络发送DNS请求,域名为“_services._dns-sd._udp.local”,这将引起本地网络中所有提供服务的主机都向被攻击者IP发送DNS响应,列举网络中所有服务

    MDNS Reflection DDoS 2015年3月,有报告叙述了mDNS 成为反射式和放大式 DDoS 攻击中所用媒介的可能性,并详述了 mDNS 反射式攻击的原理和相应防御方式.Q3,Akam ...

  4. [湖南师大集训2018 7 26] hunger 解题报告 (SPFA)

    饿 (hungry.pas/c/cpp) [背景描述] 给出

  5. C# App.config 自定义 配置节 出现的问题:配置系统未能初始化

    C# 读取app.config配置文件 节点键值,提示 "配置系统未能初始化" 错误的解决方案 新建C#项目,在app.config中添加了appSettings项,运行时出现&q ...

  6. 1893. [国家集训队2011]等差子序列(bitset)

    ★★   输入文件:nt2011_sequence.in   输出文件:nt2011_sequence.out   简单对比时间限制:0.3 s   内存限制:512 MB [试题来源] 2011中国 ...

  7. JACOB调用控件函数

    背景介绍: 使用JAVA程序,实现对系统已安装控件方法的调用. JACOB下载地址:http://danadler.com/jacob/ 使用方法: 1.将jacob.jar添加到项目工程中 2.将j ...

  8. Map<String,String>转换json字符串

    import java.util.HashMap; import java.util.Map; import net.sf.json.JSONObject; public class testJson ...

  9. [NOIP2014提高组]联合权值

    题目:洛谷P1351.Vijos P1906.codevs3728.UOJ#16. 题目大意:有一个无向连通图,有n个点n-1条边,每个点有一个权值$W_i$,每条边长度为1.规定两个距离为2的点i和 ...

  10. 装了ubuntu后笔记本电脑的无线网卡用不了,怎么设置?

    百度经验的一篇文章 http://jingyan.baidu.com/article/ca2d939dd4f1b4eb6c31ce09.html 点击右上角的齿轮,选择“系统设置”   点击“软件和更 ...