https://acs.jxnu.edu.cn/problem/ICPCJX2021B
Continued Fraction
1000ms 262144K
描述:
A continued fraction is an expression of the form:
a0+1a1+1a2+1⋱+1ana0+1a1+1a2+1⋱+1an
where a0,a1,…,ana0,a1,…,an are nonnegative integers.
Given a fraction xyxy(x,yx,y are positive integers), please expand it into a continued fraction.
输入:
The first line contains an integer T(1≤T≤103)T(1≤T≤103), denoting the number of test cases.
The only line of each test case contains two integers x,y(1≤x,y≤109)x,y(1≤x,y≤109), denoting a fraction xyxy. It's guaranteed that gcd(x,y)=1gcd(x,y)=1.
输出:
For each test case, output one line: first an integer nn denoting the height of the continued fraction, then n+1n+1 integers denoting a0,…,ana0,…,an. Your solution should gurarantee that 0≤n≤1000,0≤ai≤1090≤n≤1000,0≤ai≤109.
If there are multiple valid solutions, you only need to output one of them.
样例输入:
2 105 38 1 114
样例输出:
4 2 1 3 4 2 1 0 114
注释:
For the convenience of you, we give explanation of sample:
10538=2+11+13+14+1210538=2+11+13+14+12
1114=0+1114
题目大意:
连续分数是形式的表达式:
ao+1a1+1a2+1.+1anaO+1a1+1a2+1‘.+1AN
其中a0,a1.a0,a1.an是非负整数。
给定分数xyxy(x,yx,y是正整数),请将其展开为连续分数。
输入:
第一行包含一个整数T(1≤T≤103)T(1≤T-103),表示测试用例的数目。每个测试用例的唯一行包含两个整数,y(1≤x,y≤10 9)x,y(1≤x,y≤109),表示X。保证了gcd(x,y)=1gcd(x,y)=1。
输出:
对于每个测试用例,输出一行:首先一个整数nn表示连续分数的高度,然后n+1n+1个整数表示0.分析.an。您的解决方案应该保证O≤n≤1000,0≤ai≤1090≤n≤1000,0≤ai≤109。
如果有多个有效的解决方案,您只需要输出其中一个。
样例输入:
2 105 38 1 114
样例输出:
4 2 1 3 4 2 1 0 114