CSUOJ 1638 Continued Fraction
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
#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的更多相关文章
- HDU - 3556 - Continued Fraction
先上题目: Continued Fraction Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Jav ...
- Continued Fractions CodeForces - 305B (java+高精 / 数学)
A continued fraction of height n is a fraction of form . You are given two rational numbers, one is ...
- CF 305B——Continued Fractions——————【数学技巧】
B. Continued Fractions time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- 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 ...
- 欧拉工程第65题:Convergents of e
题目链接 现在做这个题目真是千万只草泥马在心中路过 这个与上面一题差不多 这个题目是求e的第100个分数表达式中分子的各位数之和 What is most surprising is that the ...
- BCTF warmup 50
这是一道关于RSA的解密题:首先,我们要明白,通常是公钥加密.私钥解密,私钥签名.公钥验证.这个题目中给出的是一个公钥和一段密文. 刚开始一直以为和验证签名有关,费劲脑汁也想不出来怎么办.下面介绍些思 ...
- (Problem 57)Square root convergents
It is possible to show that the square root of two can be expressed as an infinite continued fractio ...
- C++开源库集合
| Main | Site Index | Download | mimetic A free/GPL C++ MIME Library mimetic is a free/GPL Email lib ...
- Exercises for IN1900
Exercises for IN1900October 14, 2019PrefaceThis document contains a number of programming exercises ...
随机推荐
- Android OpenGL ES(七)----理解纹理与纹理过滤
1.理解纹理 OpenGL中的纹理能够用来表示图像.照片,甚至由一个数学算法生成的分形数据.每一个二维的纹理都由很多小的纹理元素组成.它们是小块的数据,类似于我们前面讨论过的片段和像素.要使用纹理,最 ...
- mysql-基础和基本指令
基础: 1.数据库模式:简单的说:就是一个数据库用户所拥有的数据库的对象. 比如scott用户建立了表,索引,视图,存储过程等对象,那么这些对象就构成了schema scott .有时用作数据 ...
- sass05 数据类型,数据运算
/*! 数字类型 */ $n1: 1.2; $n2: 12; $n3: 14px; p{ font-size: $n3; } /*! 字符串类型*/ $s1: container; $s2: 'con ...
- Mysql优化理论知识
参考文章 http://blog.51cto.com/lizhenliang/2095526 ()硬件优化 如果有条件一定要SSD固态硬盘代替SAS机械硬盘,将RAID级别调整为RAID1+,相对于R ...
- json的认识及对json数据的相互转化
Json 和 Jsonlib 的使用 什么是 Json JSON(JvaScript Object Notation)(官网网站:http://www.json.org/)是 一种轻量级的数据交换格式 ...
- metasploit.meterpreter学习笔记(博主推荐)
Metasploit学习笔记(博主推荐) 继续上面的博客 metasploit.meterpreter的基本使用: 首先来获取当前系统(即xp)下的正在运行的一些进程 获得进程之后,我们通过migra ...
- 如何安装MySQL?(二)
MYSQL的两种安装方式 MSI安装 ZIP安装 第一步: 第二步: 第三步: 这里我选择下载到桌面吧! 第四步: 第五步: 第六步: 第七步: 典型安装:除了安装MySQL的服务器,还安装MySQL ...
- Java基础学习(三) -- OOP的三大特征、向上和向下转型、内部类之详解
面向对象编程(OOP)的三大特征 什么是封装? (1) 把对象的状态和行为看成一个统一的整体,将二者存放在一个独立的类中; (2) "信息隐藏", 把不需要让外界知道的信息隐藏起来 ...
- 安卓通过Json注册登录
对于刚开始做安卓的来说,可能一个好的Demo比什么都来得快,但是最近在做安卓登录注册的时候,发现基本找不到我想要的东西,无奈只好硬着头皮做,好在不负付出,终于搞定,也算是给自己一个交待. 从结构上说, ...
- cnmp安装失败,报错npm ERR! enoent ENOENT: no such file or directory,
1.cnmp安装失败 2.提示如下: bogon:node_modules liangjingming$ sudo npm install cnpm -g --registry=https://reg ...