The function sigma 1, σ1 in mathematics, is known as the one that gives the sum of the divisors of an integer number.

For example for the number 10,
```python
σ1(10) = 18 # because the divisors of 10 are: 1, 2, 5, 10

σ1(10) = 1 + 2 + 5 + 10 = 18
```
You can see the graph of this important function up to 250:



The number 528 and its reversed, 825 have equal value for the function σ1.
```python
σ1(528) = σ1(825)

divisors of 528 are: 1, 2, 3, 4, 6, 8, 11, 12, 16, 22, 24, 33, 44, 48, 66, 88, 132, 176, 264 and 528

the sum of the divisors of 528 is 1488

divisors of 825 are: 1, 3, 5, 11, 15, 25, 33, 55, 75, 165, 275 and 825

the sum of the divisors of 825 is 1488
```
In fact 528 is the smallest non palindromic integer that has this property.

We need a function, ```equal_sigma1()```, that may collect all the positive integers that fulfill the property described above.

The function receives an upper limit, ```nMax```, will output the total sum of these numbers and its reversed while are less or equal nMax.

Let's see some cases:
```python
equal_sigma1(100) = 0 # There are no numbers.

equal_sigma1(1000) = 1353 # 528 and its revesed 825 were found, 528 +  825 = 1353

equal_sigma1(2000) = 4565 # There are four numbers_: 528 + 825 + 1561 + 1651 = 4565

equal_sigma1(1600) = 2914 # Now we have three numbers: 528 + 825 + 1561 = 2914

equal_sigma1(1561) = 2914
```
The palindromic numbers (like 88, 808, 929), numbers that are equal to its reversed should be discarded.

Happy coding!!

(For more information about the general sigma function see at: https://en.wikipedia.org/wiki/Divisor_function)

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code: def sigma1(n):
	

Solutions:
cache = {}

def sum_div(x):
	if x not in cache:
		cache[x] = sum((i for i in range(1, x + 1) if x % i == 0))
	return cache[x]

def is_required(x):
	reversed = int(str(x)[::-1])
	return x != reversed and sum_div(x) == sum_div(reversed)
required = [x for x in range(528, 10 ** 4) if is_required(x)]

def equal_sigma1(nMax):
	return sum((x for x in required if x <= nMax))


def sigma1(n):
	ans = 0
	for i in xrange(1, int(n ** 0.5) + 1):
		if n % i == 0:
			ans += i + n / i
	return ans if n ** 0.5 % 1 != 0 else ans - int(n ** 0.5)

def equal_sigma1(n_max):
	ans = 0
	for i in xrange(528, n_max + 1):
		j = int(str(i)[::-1])
		if i != j and sigma1(i) == sigma1(j):
			ans += i
	return ans


import bisect

def s1(n):
	result = 0
	for i in range(1, int(n ** 0.5) + 1):
		(q, r) = divmod(n, i)
		if r == 0:
			result += i
			if q != i:
				result += q
	return result
dup = set()
for i in range(10001):
	ss = str(i)
	rr = ss[::-1]
	if ss >= rr:
		continue
	if s1(i) == s1(int(rr)):
		dup.add(i)
		dup.add(int(rr))
dup = sorted(dup)

def equal_sigma1(nMax):
	return sum(dup[:bisect.bisect(dup, nMax)])


def sigma1(n):
	return sum(set(sum(([k, n // k] for k in range(2, int(n ** 0.5) + 1) if not n % k), [1, n])))

def equal_sigma1(limit):
	return sum((n for n in range(limit + 1) if n != int(str(n)[::-1]) and sigma1(n) == sigma1(int(str(n)[::-1]))))


n = 100000
s = list(range(1, n + 2))
for d in range(2, int(n ** 0.5) + 1):
	for i in range(d * d, n + 1, d):
		s[i] += d
		s[i] += i // d
	s[d * d] -= d

def equal_sigma1(n):
	return sum((x for x in range(n + 1) if str(x) != str(x)[::-1] and s[x] == s[int(str(x)[::-1])]))


import math

def find_sum_of_divisors(number):
	not_divisible = []
	sum = 1 + number
	for div in xrange(2, int(round(math.sqrt(number) + 1))):
		if number % div == 0:
			sum += div + number / div
	return sum

def equal_sigma1(nMax):
	checked_numbers = set()
	found_sum = 0
	for num in xrange(528, nMax + 1):
		if num in checked_numbers:
			continue
		number = str(num)
		rev_number = number[::-1]
		rev_num = int(rev_number)
		checked_numbers.add(num)
		checked_numbers.add(rev_num)
		if number == rev_number:
			continue
		if find_sum_of_divisors(num) == find_sum_of_divisors(rev_num):
			found_sum += num + (rev_num if rev_num <= nMax else 0)
	return found_sum


def sigma(n):
	r = 0
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			r += i + n // i
	if n ** 0.5 % 1 != 0:
		return r
	else:
		return r - int(n ** 0.5)

def equal_sigma1(nmax):
	(i, s) = (2, 0)
	while i <= nmax:
		rev = int(str(i)[::-1])
		if i != rev and sigma(i) == sigma(rev):
			s += i
		i += 1
	return s


res = [528, 825, 1561, 1651, 4064, 4604, 5346, 6435, 5795, 5975]

def equal_sigma1(nMax):
	return sum((x for x in res if x <= nMax))


f_d = lambda m: sum(set(sum([[i, m // i] for i in range(1, int(m ** 0.5) + 1) if m % i == 0], [])))
equal_sigma1 = lambda n: sum(set(sum([[i, int(str(i)[::-1]) if int(str(i)[::-1]) <= n else 0] for i in range(2, n + 1) if str(i) != str(i)[::-1] and f_d(i) == f_d(int(str(i)[::-1])) > 0], [])))


def f(n):
	r = 1 + n
	for i in range(2, int(n ** 0.5) + 1):
		if not n % i:
			r += i
			j = n // i
			if i != j:
				r += j
	return r
s = set()
for i in range(528, 10000):
	j = int(str(i)[::-1])
	if i != j and f(i) == f(j):
		s |= {i, j}

def equal_sigma1(n):
	return sum((x for x in s if x <= n))