Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

An Arithmetic Problem

Limits 1s, 512 MB

A sequence is an arithmetic sequence if every two successive number has same difference. Suppose this is a sequence of numbers:

a1a_1, a2a_2, a3a_3, …, ana_n

This is an arithmetic sequence if aiai+1a_i - a_{i+1} is same for each i from 1 to n1n-1.

You are given first 3 terms of a sequence and the value of nn. If it is an arithmetic sequence you must print the nn-th term. Otherwise you must print “Error”.


In the first line there will be an integer TT (1T20001 ≤ T ≤ 2000) denoting number of test cases. Each of the case will contain 4 integers a1a_1, a2a_2, a3a_3 (300a1,a2,a3300-300 ≤ a_1, a_2, a_3 ≤ 300) and nn (1n10001 ≤ n ≤ 1000).


In each line specify the case number and print the answer.


1 2 3 10
1 4 3 10
15 30 45 5
Case 1: 10
Case 2: Error
Case 3: 75



79% Solution Ratio

rakeenEarliest, Aug '15

emrulk1Fastest, 0.0s

Mohaimin66Lightest, 0 B

bokaifShortest, 118B


Login to submit

Toph uses cookies. By continuing you agree to our Cookie Policy.