编程介的小学生
2018-12-07 15:34
采纳率: 92.6%
浏览 475

判断一个序列是不是等比级数。用C语言解答这个问题怎么做呢?

Problem Description
Determine whether a sequence is a Geometric progression or not.

In mathematics, a geometric progression, also known as a geometric sequence, is a sequence of numbers where each term after the first is found by multiplying the previous one by a fixed, non-zero number called the common ratio. For example, the sequence 2, 6, 18, 54, ... is a geometric progression with common ratio 3. Similarly 10, 5, 2.5, 1.25, ... is a geometric sequence with common ratio 1/2.

Examples of a geometric sequence are powers rk of a fixed number r, such as 2k and 3k. The general form of a geometric sequence is

a, ar, ar2, ar3, ar4, …

where r ≠ 0 is the common ratio and a is a scale factor, equal to the sequence's start value.

Input
First line contains a single integer T(T≤20) which denotes the number of test cases.

For each test case, there is an positive integer n(1≤n≤100) which denotes the length of sequence,and next line has n nonnegative numbers Ai which allow leading zero.The digit's length of Ai no larger than 100.

Output
For each case, output "Yes" or "No".

Sample Input
4
1
0
3
1 1 1
3
1 4 2
5
16 8 4 2 1

Sample Output
Yes
Yes
No
Yes

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • threenewbee 2019-03-28 23:46
    已采纳
    已采纳该答案
    打赏 评论
  • 潭溪Zerg 2018-12-08 01:39
        if len < 3: return Yes
        rate = array[1] / array[0]
        for i : 2->len-1:
            if array[i] / array[i-1] != rate:
                return No
        return Yes
    
    打赏 评论

相关推荐 更多相似问题