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 ...
随机推荐
- vim水平摆放全部窗体的三个方法
Method1: map <F7> <ESC>:windo exe "normal \<foobar<C-W>C-W>K"<C ...
- thinkphp5的Illegal string offset 'id'错误
thinkphp5的Illegal string offset 'id'错误 问题 解答 数组同名了,一个html页面传进来两个cateres的数组,所以在找id的时候不知道找这两个里面的哪一个 第一 ...
- react --- React中state和props分别是什么?
props React的核心思想就是组件化思想,页面会被切分成一些独立的.可复用的组件. 组件从概念上看就是一个函数,可以接受一个参数作为输入值,这个参数就是props,所以可以把props理解为从外 ...
- Bayes++ Library入门学习之熟悉class-Bayesian_filter_base(2)
前面我们已经熟悉了Bayesian_filter::Bayes_filter_base和其子类的击继承关系,接下来我们开始学习该类的实现. bayesFlt.hpp文件为其实现主体,首先是两个常规的头 ...
- PL/SQL Developer 关闭Sql窗口快捷键
preferences->keyconfigration->file/close然后设置你喜欢的按键就行了.(ps:这个close是关闭当前活动的那一个页面)
- 临时的js方法
//楼层的js var scroChange; //楼层跳转 function FloorGo(domId){//传入目标的id clearInterval(scroChange); var scro ...
- SPFA的小优化
标签:闲扯 SPFA的小优化 1. 向队尾加入元素时,如果它比对首还优,就把把它直接和队首交换. 拿一个双端队列来实现 (手写 , head ,tail STLdeque亲测及其慢) 这个小优化其 ...
- Win10 +VS2015 配置openCV3.4.0
配置过程参考链接:https://www.cnblogs.com/linshuhe/p/5764394.html 其他链接:https://blog.csdn.net/weixin_39393712/ ...
- HDU 4960 Another OCD Patient 简单DP
思路: 因为是对称的,所以如果两段是对称的,那么一段的前缀和一定等于另一段的后缀和.根据这个性质,我们可以预处理出这个数列的对称点对.然后最后一个对称段是从哪里开始的,做n^2的DP就可以了. 代码: ...
- ArcGIS api for javascript——加入动态地图
描述 这个示例展示了增加一个按用户缩放或平移服务器每次绘制的地图.这样的地图没有切片的cache并被调用一个动态地图服务图层.ArcGISDynamicMapServiceLayer表示ArcGIS ...