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. sass08 if while for each

    scss @function getzIndex($layer: default){ $zindexMap: (default: 1, modal: 1000, dropdown: 500, grid ...

  2. emmet教程

    https://www.zfanw.com/blog/zencoding-vim-tutorial-chinese.html https://www.zfanw.com/blog/zencoding- ...

  3. BZOJ1468: Tree & BZOJ3365: [Usaco2004 Feb]Distance Statistics 路程统计

    [传送门:BZOJ1468&BZOJ3365] 简要题意: 给出一棵n个点的树,和每条边的边权,求出有多少个点对的距离<=k 题解: 点分治模板题 点分治的主要步骤: 1.首先选取一个点 ...

  4. bzoj1001: [BeiJing2006]狼抓兔子(初识是你最小割)

    1001: [BeiJing2006]狼抓兔子 题目:传送门 题解: 听说这题当初是大难题...可惜当年没有网络流hahahha 现在用网络流的思想就很容易解决了嘛 给什么连什么,注意是双向边,然后跑 ...

  5. zzulioj--1813--good string(模拟)

    1813: good string Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 93  Solved: 15 SubmitStatusWeb Boa ...

  6. 面向对象(OOP)五大基本原则

    书单 <Object-Oriented Analysis & Design with Application>:Grady Booch, 下载地址:object-oriented- ...

  7. BZOJ 1001 平面图与对偶图的转化 最短路Or最大流

    思路: 1.按照题意求最小割 转换成最大流用Dinic解 2. 转换成对偶图 求最短路 Dinic: //By SiriusRen #include <queue> #include &l ...

  8. leetcode 生成杨辉三角形, 118 119 Pascal's Triangle 1,2

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...

  9. CUDA笔记(八)

    今天真正进入了攻坚期.不光是疲劳,主要是遇到的问题指数级上升,都是需要绕道的. 以visual profile来说,刚刚发现自己还没使用过. http://bbs.csdn.net/topics/39 ...

  10. array.fliter无法正确过滤出我想要的数组

    var checked_list = state.files.filter(function(item, id){ // console.log('click the ' + item.id); re ...