AP2 - AP - Complete The Series (Easy)

no tags 

Arithmatic and geometric Progressions are 2 of the well known progressions in maths.

Arithmatic progression(AP) is a set in which the difference between 2 numbers in constant. for e.g., 1, 3, 5, 7, 9 .... In this series the difference between 2 numbers is 2.

The task here is very simple indeed.

You will be given the 3rd term , 3rd last term and the sum of the series. You need print length of the series & the series.


First line will contain a number indicating the number of test cases.

Each of the following t lines will have 3 number '3term' ,'3Lastterm' and 'sum'

3termĀ  - is the 3rd term in of the series and

3LasttermĀ  - is the 3rd term in of the series and

sum - is the sum of the series.


For each input of the test case, you need to print 2 lines.

First line should have 1 value - the number of terms in the series.

2nd line of the output should print the series numbers separated by single space.


3 8 55

1 2 3 4 5 6 7 8 9 10


  • In all the test cases, all the series elements are positive integers.
  • The series will have at least 7 elements.
  • number of test cases <=100.
  • All the numbers will fit in 64 bits (long long in C)

hide comments
true_saiyan: 2017-11-22 15:50:24

Check for case where 3rd term and 3rd last term are equal in python. Cost me 2WA

dinesh6752: 2017-10-16 21:24:33

high school math :)

hitesh87: 2017-09-30 10:40:10

Got WA for int. AC in long long:p

prasanth292130: 2017-09-02 20:09:41

Pure math!!!!!!!
AC in one go

madhur4127: 2017-08-26 07:33:48

1 WA for not printing N, avoid!

hkuadithya: 2017-08-18 07:12:04

Big HINT. Don't try some long mind fuck formula.
Read this only if you are stuck.
Sn = (n/2) * (3Term + 3LastTerm) . Try to derive this formula.

Last edit: 2017-08-18 07:12:57
dexter_9: 2017-08-06 12:58:20

are all input series AP ?

ramesh_961: 2017-05-29 09:29:28

Easy Think cool!! n>=6(no of elements) in all test cases!!

sagnik_66: 2017-05-19 20:09:55


polkerty: 2017-03-16 04:19:26

Wow... do not over think this problem. It's rated as one of the easiest ones here, but if you approach it wrong you can get many WAs. Don't use binary search. Don't do anything involving quadratics or powers. ... This has scarred me haha

Added by:Devil D
Time limit:0.100s
Source limit:1500B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64