Harold always boasted about his prowess with numbers. So one day Reese challenged him to…
- User
Harold always boasted about his prowess with numbers. So one day Reese challenged him to a problem. He gave Harold two numbers X and Y and asked him to find out the N^th number of the series which began with X numbers of Y’s and the following elements are equal to the sum of the last X numbers in the series. Help Harold find the N^th number of the series. Input: The first line contains a number T , number of test cases. The next T lines each contain 3 integers X, Y and N separated by single space.
Output: For each test case print the N^th number of the sequence.
Constraints: 1 ≤ T ≤ 10^6 0 < N ≤ 50 0 < X < 50 0 ≤ Y< 3
Problem statement in native language : http://hck.re/F91Yaz
SAMPLE INPUT 1 3 2 7
SAMPLE OUTPUT 34
Explanation
For X=3,Y=2 the series will be as follow: 2, 2, 2, 6, 10, 18, 34
Assistant
pythonimport sys def main(): # Precompute the memoization table memo = [[[0] * 51 for _ in range(3)] for __ in range(50)] # X can be 1-49, Y 0-2, N 1-50 for X in range(1, 50): for Y in range(3): seq = [Y] * X while len(seq) < 50: next_val = sum(seq[-X:]) seq.append(next_val) for n in range(1, 51): if n <= len(seq): memo[X][Y][n] = seq[n-1] # Read all input and process data = sys.stdin.read().split() idx = 0 T = int(data[idx]) idx += 1 results = [] for _ in range(T): X = int(data[idx]) Y = int(data[idx+1]) N = int(data[idx+2]) idx +=3 results.append(memo[X][Y][N]) # Print all results sys.stdout.write('\n'.join(map(str, results)) + '\n') if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.