Problem Statement
Design a generator Geometric_Sequence
that can accept 2 parameters, where the first parameter represents the first item of the geometric sequence, and the second parameter indicates the common ratio of this sequence.
Because the number will be increasing exponentially, you should take the modulus of 100 each time you yield the number.
You can start with this template code and ensure your code can run correctly within this template:
def Geometric_Sequence(first,common_ratio):
#Your code here
pass
# Note that the following code is for local testing purposes only. You should leave this part of code unchanged and not submit it to the OJ system.
T = int(input())
for i in range(1,T+1):
n,f,cr = list(map(int,input().split()))
g = Geometric_Sequence(f,cr)
for j in range(n):
print(f"Case #{i}_{j}: {next(g)}")
Please note that you only have to submit the definition of the Geometric_Sequence
and its content to the OJ system. The rest of the code is for your local testing purposes only.
Input Specification
The first line of the input contains a single integer T, the number of test cases.
For each test case, there is one line:
The line contains three positive integer ,,.These integers represent the number of times we call next()
,the first item of this geometric sequence and the common ratio of this sequence,respectively.
Constraints
Output Specification
For each function call, you must return exactly what we asked for.
Sample Input
1
10 1 2
Sample Output
Case #1_0: 1
Case #1_1: 2
Case #1_2: 4
Case #1_3: 8
Case #1_4: 16
Case #1_5: 32
Case #1_6: 64
Case #1_7: 28
Case #1_8: 56
Case #1_9: 12
Explaination
The first ten items of this geometric sequence are:
1 2 4 8 16 32 64 128 256 512
After we apply the modulus 100 operation on each item, it becomes:
1 2 4 8 16 32 64 28 56 12
Therefore, the expected output is:
Case #1_0: 1
Case #1_1: 2
Case #1_2: 4
Case #1_3: 8
Case #1_4: 16
Case #1_5: 32
Case #1_6: 64
Case #1_7: 28
Case #1_8: 56
Case #1_9: 12
Hint
generator
Comments