Continued Fraction(https://acs.jxnu.edu.cn/problem/ICPCJX2021B)

该博客介绍了如何将给定的正整数分数转换为连分数形式。内容涉及连分数的基本概念,以及如何通过非负整数序列来表示分数。题目要求在限制条件下找到并输出连分数的表示,包括其长度和组成元素。对于每个测试案例,输出连分数的长度和相关整数序列,确保解的合法性。
摘要由CSDN通过智能技术生成

描述:

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.

翻译:连分数有一下形式,其中a0,a1...an为非负整数.给定一个分数x/y(x,y都为正整数),将他们以连分数的形式表示.

输入:第一行为一个整数T(1<=T<=10E3),代表测试样例数.每个测试样例一行,两个整数x,y(1<=x,y<=10E9).代表一个分数x/y,并且保证x和y最大公约数为1.

输出:每个测试样例一行,第一个整数n代表的连分数的长度.然后n+1个整数标记为a0...an你的方案应该保证0<=n<=1000,0<=ai<=10E9.

如果有多种解决方案,你只需要输出其中一个

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值