英语翻译14

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值