Due to another of his misbehaved, 
the primary school's teacher of the young Gauß,  Herr J.G. Büttner, to keep the bored and unruly young schoolboy Karl Friedrich Gauss busy for a good long time, while he teaching arithmetic to his mates,
assigned him the problem of adding up all the whole numbers from 1 through a given number `n`.

Your task is to help the young Carl Friedrich to solve this problem as quickly as you can; so, he can astonish his teacher and rescue his recreation interval.

Here's, an example:

```
f(n=100) // returns 5050 
```

It's your duty to verify that n is a valid positive integer number. If not, please, return false (None for Python, null for C#).

> **Note:** the goal of this kata is to invite you to think about some 'basic' mathematic formula and how you can do performance optimization on your code. 

> Advanced - experienced users should try to solve it in one line, without loops, or optimizing the code as much as they can.

-----

**Credits:** this kata was inspired by the farzher's kata 'Sum of large ints' . In fact, it can be seen as a sort of prep kata for that one.

Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code:
def f(n):
	

Solutions:
def f(n):
	return n * (n + 1) // 2 if isinstance(n, int) and n > 0 else None


def f(n):
	return sum(range(1, n + 1)) if type(n) is int and n > 0 else None


def f(n):
	try:
		return None if n <= 0 else sum(range(1, n + 1))
	except:
		return None


def f(n):
	return None if type(n) != int or n < 1 else n * (n + 1) / 2


def f(n):
	return (n + 1) * n // 2 if type(n) is int and n > 0 else None


from functools import reduce

def f(n):
	return None if not isinstance(n, int) or n < 1 else reduce(lambda x, y: x + y, range(1, n + 1))


def f(n):
	try:
		x = int(n)
		if int(n) < 0:
			return None
		elif int(n) > 0:
			return sum([i for i in range(0, n + 1)])
	except:
		None


from numbers import Number

def f(n):
	return n * (n + 1) / 2 if isinstance(n, int) and n > 0 else None


f = lambda n: (n ** 2 + n) // 2 if type(n) == int and n > 0 else None


def f(n):
	return (isinstance(n, int) and n > 0) and n * (n + 1) / 2 or None


f = lambda n: n * (n + 1) / 2 if type(n) is int and n > 0 else None


def f(n):
	try:
		if n > 0 and type(n) is int:
			return int(n * (n + 1) / 2)
	except:
		return None


def f(n):
	if type(n) == int and n > 0:
		return (1 + n) * n / 2
	elif type(n) == str or type(n) == float or n < 0:
		return None
	else:
		return None


def f(n):
	if isinstance(n, int):
		if n > 0:
			sum = 0
			for i in range(0, n + 1):
				sum = sum + i
			return sum
	return None


def f(n):
	if type(n) != int:
		return None
	return sum([x for x in range(n + 1)]) if n > 0 else None


def f(n):
	n_ = None
	try:
		n_ = float(n)
	except:
		return None
	return n_ * (n_ + 1) / 2 if n_.is_integer() and n_ > 0 else None


def f(n):
	if type(n) is not int or n <= 0:
		result = None
	else:
		lst = [i for i in range(0, n + 1)]
		result = sum(lst)
	return result


def f(n):
	if type(n) != int:
		return None
	if n > 0:
		return n * (n + 1) / 2
	return None


def f(n):
	tot = 0
	if type(n) == int and n > 0:
		for number in range(1, n + 1):
			tot += number
		return tot
	return None


def f(n):
	if isinstance(n, int) and n > 0:
		nn = [i for i in range(n + 1)]
		return sum(nn)


def f(n):
	if type(n) == str or type(n) == float or n < 1:
		return None
	return sum(range(1, n + 1))


def f(n):
	return None if type(n) in [str, float] or n < 1 else sum([i for i in range(0, n + 1)])


def f(n):
	try:
		return n * (n + 1) / 2 if n > 0 and n - round(n) == 0 else None
	except TypeError:
		return None


def f(n):
	if isinstance(n, int) and n > 0:
		return n * (n + 1) / 2


def f(n):
	if type(n) == int and n > 0:
		return n / 2 * (n + 1)


def f(n):
	if type(n) == int and n > 0:
		return sum(range(1, n + 1))


f = lambda n: int == type(n) and n > 0 and -~n * n / 2 or None


def f(n):
	if type(n) is int and n >= 1:
		number_of_elements = n / 2
		total_elements = (n + 1) * number_of_elements
		return total_elements
	else:
		return None


def f(n):
	print('The number is' + str(n))
	if n == 1:
		return n
	if type(n) != int or n <= 0:
		return None
	return n / 2 * (n + 1)


def f(n):
	return sum(list(range(0, n + 1))) if isinstance(n, int) and n > 0 else None


def f(n):
	try:
		val = int(n)
		if val <= 0:
			return None
	except ValueError:
		return None
	else:
		i = 0
		nums = []
		while i < n:
			if type(n) != int:
				return None
			else:
				i += 1
				nums.append(i)
		return sum(nums)


def f(n):
	n = n
	total = 0
	if type(n) != int:
		return None
	if n <= 0:
		return None
	while n >= 0:
		total += n
		n -= 1
	return total


def f(n):
	if isinstance(n, str):
		return None
	if n <= 0:
		return None
	if n != int(n):
		return None
	return n * (n + 1) // 2


def f(n):
	if isinstance(n, str):
		return None
	if isinstance(n, float):
		return None
	if n <= 0:
		return None
	count = 0
	for i in range(n + 1):
		count += i
	return count


def f(n):
	if isinstance(n, int) and n > 0:
		sum = 0
		while int(n) > 0:
			sum += n
			n -= 1
		return sum
	return None


def f(n):
	total = 0
	if isinstance(n, int) and n > 0:
		for b in range(0, n + 1, 1):
			total = total + b
		return total
	else:
		return None


def f(n):
	return sum(range(1, n + 1, 1)) if str(n).isdigit() and int(n) > 0 else None


def f(n):
	if isinstance(n, int) == False or n <= 0:
		return None
	else:
		sum = 0
		for i in range(1, n + 1):
			sum += i
		return sum


def f(n):
	if not isinstance(n, int):
		return
	result = 0
	for x in range(n + 1):
		result += x
	return result if result > 0 else None


def f(n):
	if not type(n) == int or not n > 0:
		return
	else:
		result = (n + 1) * (n / 2)
	return result


def f(n):
	if type(n) == str:
		return None
	elif n < 0:
		return None
	if type(n) == float:
		return None
	if n == 0:
		return None
	suma = 0
	for i in range(n + 1):
		suma += i
	return suma


def f(n):
	if type(n) == int and n > 0:
		a = 0
		sum = 0
		while a < n:
			a = a + 1
			sum = sum + a
		return sum


def f(n):
	if isinstance(n, int) and n > 0:
		return sum((x for x in range(1, n + 1)))


def f(n):
	if type(n) == int:
		counter = 0
		if n > 0:
			for i in range(n + 1):
				counter += i
		if counter > 0:
			return counter
		else:
			return None
	return None


def f(n):
	if type(n) != int:
		return None
	if n <= 0:
		return None
	if n == int(n):
		return 0.5 * n * (n + 1)
	else:
		return None


def f(n):
	if isinstance(n, int) == True and n > 0:
		return sum(range(0, n + 1))


def f(n):
	print(n)
	if isinstance(n, int) and n > 0:
		x = 0
		y = 0
		while x <= n:
			y += x
			x += 1
		return y
	else:
		return None


def f(n):
	return sum([x for x in range(n + 1)]) if isinstance(n, int) and n >= 1 else None


from math import factorial

def f(n):
	if type(n) != int:
		return None
	else:
		if n <= 0:
			return None
		p = 0
		for k in range(1, n + 1):
			p += k
		return p


def f(n):
	if isinstance(n, int) and n > 0:
		return sum([a for a in range(0, n + 1)])
	else:
		return None


def f(n):
	if isinstance(n, int) != True or n <= 0:
		return None
	elif n == 1:
		return 1
	else:
		return (1 + n) * (n / 2)


def f(n):
	x = []
	if type(n) == int and int(n) > 0:
		n = abs(n)
		for i in range(1, n + 1):
			x.append(i)
		return sum(x)
	else:
		return None


def f(n):
	if isinstance(n, int) == True:
		if n > 0:
			sum = 0
			for num in range(0, n + 1, 1):
				sum = sum + num
			return sum
		else:
			None
	else:
		return None


def f(n):
	if type(n) == int and n > 0:
		num = 0
		for i in range(n + 1):
			num += i
		return num