AP2 - AP - Complete The Series (Easy)
Arithmetic and geometric Progressions are 2 of the well known progressions in maths.
Arithmetic 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 and the series.
Input
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.
Output
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.
Example
Input: 1 3 8 55 Output: 10 1 2 3 4 5 6 7 8 9 10
NOTE:
- 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
shashank4844:
2024-06-18 03:33:49
SPOJ has language acceptance problem . Same logic code , C++ is accepted while Java is giving TLE |
|
pranathi2004:
2023-04-05 07:57:54
1st time showing TLE and 2nd time AC.....xD |
|
ayush_vardhan:
2023-01-06 12:03:41
What is this happening..!!! My code got accepted in C but same code in java, was showing TLE..!!!??? Can anyone tell me why this is happening..??? |
|
slawek93:
2022-02-06 17:31:40
It seems that solution depends on programming language - I tried Java first and it didn't work. But almost the same program in c++ is accepted |
|
lvisser_code:
2021-05-20 00:12:56
Finally! Python 3 AC in 0.24s. Had to keep tweaking the print loop until found one fast enough. |
|
karthickshiva:
2020-10-26 08:33:02
You can solve this in O(1) time. Also, Java or Python doesn't matter for this problem. Quit whining. Improve your efficiency. |
|
master_ds777:
2020-10-09 19:44:46
(s/s1)*2 gives WA whereas (s*2)/s1 gives AC |
|
harshh3010:
2020-10-03 14:02:58
running loop for i=1 to n and printing a + (i-1)d in each step helped me get rid of tle in c++
|
|
navdeep1469:
2020-06-06 13:27:58
wtf .....same code got acc in c but not in c++ Last edit: 2020-06-06 13:30:17 |
|
adarshgaur:
2020-05-26 15:47:40
What the heck it is !!!! First got TLE and submiting the same code later gave AC ! |
Added by: | Devil D |
Date: | 2012-03-13 |
Time limit: | 0.100s |
Source limit: | 1500B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | Own |