CPU: 1s
Memory: 1024MB
একটি সমান্তর ধারা হল এমন একটি ধারা যার পরপর দুইটি পদের মধ্যে পার্থক্য সমান। উদাহরণস্বরূপ, 5, 7, 9, 11, 13, 15 … এটি একটি সমান্তর ধারা যার সাধারণ অন্তর 2. এই ধারার পরবর্তী পদ 15 + 2 = 17. একইভাবে, 10, 7, 4 … এটিও একটি সমান্তর ধারা এবং এর সাধারণ অন্তর -3.
একটি গুণোত্তর ধারা হল এমন একটি ধারা যার পরপর দুইটি পদের মধ্যে অনুপাত সমান। উদাহরণস্বরূপ, 2, 6, 18, 54, 162 … এটি একটি গুণোত্তর ধারা যার সাধারণ অনুপাত 3. এই ধারার পরবর্তী পদ 162 * 3 = 486.
N সংখ্যক পদের একটি ধারা দেওয়া থাকবে, তোমার কাজ হল ধারাটির (N+1) তম পদ নির্ণয় করা। প্রদত্ত ধারাটি হয় সমান্তর অথবা গুণোত্তর ধারা হবে এবং ধারাটি গুণোত্তর ধারা হলে এর সাধারণ অনুপাত একটি পূর্ণসংখ্যা হবে। (N+1) তম পদটি একটি integer দ্বারা প্রকাশ করা যাবে।
An arithmetic sequence is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, the sequence 5, 7, 9, 11, 13, 15 … is an arithmetic sequence with common difference of 2. The next term of this sequence is 15 + 2 = 17. Similarly, 10, 7, 4 … is also an arithmetic sequence with common difference of -3.
A geometric sequence, on the other hand, is a sequence of numbers such that the ratio between the consecutive terms is constant. For instance, the sequence 2, 6, 18, 54, 162 … is a geometric sequence with common ratio of 3. The next term of this sequence is 162 * 3 = 486.
Given a sequence of N integer numbers, your task is to predict the (N+1)th term in the sequence. The given sequence is guaranteed to be either an arithmetic sequence or a geometric sequence. In case it is a geometric sequence, the ratio is guaranteed to be an integer number. The (N+1)th term is guaranteed to fit in an integer variable.
ইনপুটের বর্ণনা
ইনপুটের প্রথম লাইনে টেস্টকেসের সংখ্যা T (1 <= T <= 100) দেওয়া থাকবে। এর পরে T টি টেস্টকেসের বর্ণনা থাকবে। প্রতিটি টেস্টকেসের প্রথম লাইনে একটি পূর্ণসংখ্যা N (3 <= N <= 1000) দেওয়া থাকবে এবং পরবর্তী লাইনে স্পেস দিয়ে আলাদা করা N টি পূর্ণসংখ্যা থাকবে, যেগুলি হল ধারাটির প্রথম N টি পদ।
Input
The first line of the input contains the number of test cases, T (1 <= T <= 100). Then T test cases follow. Each case will consist of one line containing a single integer N (3 <= N <= 1000), followed by a line containing N space-separated integers, which are the first N terms of the sequence.
অাউটপুটের বর্ণনা
প্রতিটি টেস্টকেসের জন্য একটি লাইনে একটি পূর্ণসংখ্যা X আউটপুট দিতে হবে, যেখানে X হল প্রদত্ত ধারাটির (N+1) তম পদ।
Output
For each test case, output one line containing a single integer X, where X is the (N+1)th term of the given sequence.
Sample
Input | Output |
---|---|
3 6 5 7 9 11 13 15 3 10 7 4 5 2 6 18 54 162 | 17 1 486 |