AP Series
Practice this coding question on Coding Gurukul.
Problem statement
A concert hall has a rows-and-seats plan in which each successive row changes its seat count by a fixed amount. Calculate the value at a requested row. Your task Given the first term a, common difference d, and one-based position n of an arithmetic progression, compute its nth term. Important details The first term occupies position one, so reaching position n involves n - 1 changes. The difference may be negative or zero, and the abstract progression may contain negative values. Do not compute the sum of all terms. Use the formula a + (n - 1) * d and choose an integer type that holds the intermediate product and result. Worked example With a = 5, d = 3, and n = 4, the terms start 5, 8, 11, 14. The fourth term is 14.
Input format
One line contains a d n.
Output format
Print the nth term.
Constraints
-1000000000 <= a, d <= 1000000000; 1 <= n <= 1000000000.
Sample input
5 3 4
Sample output
14
Sign in to run or submit a solution in C++, Java or Python.