A series with same common difference is known as arithmetic series. The first term of series is 'a' and common difference is d. The series looks like a, a + d, a + 2d, a + 3d, . . . Find the sum of series upto nth term.
 
Example 1:
Input: n = 5, a = 1, d = 3
Output: 35
Explanation: Series upto 5th term is
1 4 7 10 13, so sum will be 35.
Example 2:
Input: n = 3, a = 1, d = 2
Output: 9
Example: Series upto 3rd term is 
1 3 5, so sum will be 9.
 
Your Task:
You don't need to read or print anything. Your task is to complete the function sum_of_ap() which takes n, a and d as input parameter and returns the sum of the series.
 
Expected Time Complexity: O(1)
Expected Space Complexity: O(1)
 
Constranits:
1 <= n, a, d <= 10000

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3

class Solution:
	def sum_of_ap(self, n, a, d):
		# Code here

Solutions:
class Solution:

	def sum_of_ap(self, n, a, d):
		sum = 0
		for i in range(n):
			c = a + d * i
			sum += c
		return sum


class Solution:

	def sum_of_ap(self, n, a, d):
		return (2 * a + d * n - d) * n // 2


class Solution:

	def sum_of_ap(self, n, a, d):
		l = []
		for i in range(n):
			l.append(a + i * d)
		return sum(l)


class Solution:

	def sum_of_ap(self, n, a, d):
		return int(n * (2 * a + (n - 1) * d) / 2)


import math

class Solution:

	def sum_of_ap(self, n, a, d):
		return math.floor(n / 2 * (2 * a + (n - 1) * d))


class Solution:

	def sum_of_ap(self, n, a, d):
		l = []
		l.append(a)
		for i in range(1, n):
			l.append(l[i - 1] + d)
		sum = 0
		for i in range(len(l)):
			sum = sum + l[i]
		return sum


class Solution:

	def sum_of_ap(self, n, a, d):
		lst = [a]
		s = a
		for i in range(n - 1):
			s += d
			lst.append(s)
		return sum(lst)


class Solution:

	def sum_of_ap(self, n, a, d):
		x = [a]
		y = a
		for i in range(n - 1):
			y += d
			x.append(y)
		return sum(x)


class Solution:

	def sum_of_ap(self, n, a, d):
		sum = 0
		i = 0
		while i < n:
			sum = sum + a
			a = a + d
			i = i + 1
		return sum


class Solution:

	def sum_of_ap(self, n, a, d):
		sum = 0
		for _ in range(n):
			sum += a + _ * d
		return sum


class Solution:

	def sum_of_ap(self, n, a, d):
		s = n * (2 * a + (n - 1) * d) // 2
		return s


class Solution:

	def sum_of_ap(self, n, a, d):
		b = 2 * a
		c = n - 1
		e = c * d
		f = b + e
		g = f * n
		h = int(g / 2)
		return h


class Solution:

	def sum_of_ap(self, n, a, d):
		res = a
		for i in range(1, n):
			res = res + (a + i * d)
		return res


class Solution:

	def sum_of_ap(self, n, a, d):
		k = n * (2 * a + (n - 1) * d) // 2
		return k


class Solution:

	def sum_of_ap(self, n, a, d):
		sum = 0
		for i in range(2, n + 1):
			i = a + (i - 1) * d
			sum += i
		sum += a
		return sum


class Solution:

	def sum_of_ap(self, n, a, d):
		z = []
		t = a
		for i in range(n):
			z.append(t)
			t += d
		return sum(z)


class Solution:

	def sum_of_ap(self, n, a, d):
		return round((2 * a + (n - 1) * d) / 2 * n)


class Solution:

	def sum_of_ap(self, n, a, d):
		s = 0
		for i in range(0, n):
			s += a + i * d
		return s


class Solution:

	def sum_of_ap(self, n, a, d):
		c = [a]
		for i in range(n - 1):
			c.append(c[i] + d)
		return sum(c)


class Solution:

	def sum_of_ap(self, n, a, d):
		sn = n * (2 * a + (n - 1) * d) // 2
		return sn


class Solution:

	def sum_of_ap(self, n, a, d):
		Sn = n * (2 * a + (n - 1) * d) // 2
		return Sn