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. hdu5282 最长公共子序列的变形

    pid=5282">http://acm.hdu.edu.cn/showproblem.php?pid=5282 Problem Description Xuejiejie loves ...

  2. 在java项目中怎样利用Dom4j解析XML文件获取数据

    在曾经的学习.net时常常会遇到利用配置文件来解决项目中一些须要常常变换的数据.比方数据库的连接字符串儿等.这个时候在读取配置文件的时候.我们一般会用到一个雷configuration,通过这个类来进 ...

  3. An existing connection was forcibly closed by the remote host

    StackOverflow https://stackoverflow.com/questions/5420656/unable-to-read-data-from-the-transport-con ...

  4. [JZOJ4272] [NOIP2015模拟10.28B组] 序章-弗兰德的秘密 解题报告(树形DP)

    Description 背景介绍弗兰德,我不知道这个地方对我意味着什么.这里是一切开始的地方.3年前,还是个什么都没见过的少年,来到弗兰德的树下,走进了封闭的密室,扭动的封尘已久机关,在石板上知道了这 ...

  5. package & import

    /* * package:声明源文件所在的包,写在程序的第一行. * 每“.”一次,表示一层文件目录. * 包名都要小写. * * import: * 1)显式导入指定包下的类或接口 * 2)写在包的 ...

  6. 机器学习规则:ML工程最佳实践----rules_of_ml section 2【翻译】

    作者:黄永刚 ML Phase II: 特征工程 第一阶段介绍了机器学习的一个周期,为学习系统获取训练数据,通过有趣的引导设计指标,创建一个服务框架.在有了一个完整系统之后,就进入了第一阶段. 第二阶 ...

  7. Python常用目录操作(Python2)

    Python获取当前路径   Python查看指定路径下的文件和文件夹 Python修改当前工作目录(在读取文件等时需要) Python添加import路径(有时候为了import自己写的py文件,且 ...

  8. 阿里云安装mysql数据库出现2002错误解决办法

    在安装数据库的时候出现了如下错误: 解决办法如下: 1.在bin目录下 输入:kill -s 9 9907 再输入:ps -ef|grep mysql 显示如下: 2.回到lampp目录下,重启数据库 ...

  9. bzoj 1088 [SCOI2005] 扫雷

    SCOI2005 扫雷 一道很有趣的(水)题 “这道题有四种解法,你知道么” 给你矩阵的第二列的数字,求出第一列雷有多少种可能的摆法. 不懂扫雷规则的自行按win+R然后输入winmine 思考过后我 ...

  10. python虚拟环境virtualenv、virtualenv下运行IDLE、powershell 运行脚本由执行策略引起的问题

    一.为什么要创建虚拟环境: 应为在开发中会有同时对一个包不同版本的需求,创建多个开发环境就能解决这个问题.或许也会有对python不同版本的需求,这就需要使用程序来管理不同的版本,virtualenv ...