The sum of divisors of `6` is `12` and the sum of divisors of `28` is `56`. You will notice that `12/6 = 2` and `56/28 = 2`. We shall say that `(6,28)` is a pair with a ratio of `2`.  Similarly, `(30,140)` is also a pair but with a ratio of `2.4`. These ratios are simply decimal representations of fractions.

`(6,28)` and `(30,140)` are the only pairs in which `every member of a pair is 0 <= n < 200`. The sum of the lowest members of each pair is `6 + 30 = 36`. 

You will be given a `range(a,b)`, and your task is to group the numbers into pairs with the same ratios. You will return the sum of the lowest member of each pair in the range. If there are no pairs. return `nil` in Ruby, `0` in python. Upper limit is `2000`.

```Haskell
solve(0,200) = 36
```

Good luck!

if you like this Kata, please try:

[Simple division](https://www.codewars.com/kata/59ec2d112332430ce9000005)

[Sub-array division](https://www.codewars.com/kata/59eb64cba954273cd4000099)

Difficulty: introductory

Starter code:

def solve(a,b):
	

Solutions:
from collections import defaultdict
from fractions import Fraction
from bisect import bisect_left as bisect

harmonic = [0] + [Fraction(sum({y for x in range(1,int(n**.5)+1) for y in [x, n//x] if not n%x}), n) for n in range(1,7001)]

harmonicity = defaultdict(set)
for n,h in enumerate(harmonic): harmonicity[h].add(n)

HARMO_GROUPS = {h: sorted(s) for h,s in harmonicity.items() if len(s) > 1}
HARMO_RATIOS = {n: h for h,lst in HARMO_GROUPS.items() for n in lst}
HARMO_NUM    = sorted(HARMO_RATIOS.keys())

def solve(a,b):
    seens, s = set(), 0
    n1, n2 = bisect(HARMO_NUM, a), bisect(HARMO_NUM, b)
    for n in HARMO_NUM[n1:n2]:
        if n not in seens:
            grp = [x for x in HARMO_GROUPS[HARMO_RATIOS[n]] if a <= x < b]
            if len(grp) > 1:
                seens |= set(grp)
                s += grp[0]
    return s

import collections

def solve(a,b):
    d = collections.defaultdict(list)
    for n in range(a, b):
        d[(sum(k + n//k for k in range(1, int(n**0.5)+1) if n%k==0) - (int(n**0.5) if int(n**0.5) == n**0.5 else 0))/n].append(n)
    return sum(v[0] for v in list(d.values()) if len(v) > 1)


from collections import defaultdict

D = defaultdict(list)
for x in range(1, 2000):
    D[sum(y for y in range(1, x+1) if x%y == 0) / x].append(x)
result = [v for v in D.values() if len(v) >= 2]

# Fuck [6, 28, 496] and [84, 270, 1488, 1638], description was unclear
def solve(a,b):
    def check(p):
        for x in range(len(p)-1):
            if a <= p[x] and p[x+1] < b:
                return p[x]
        return 0
    return sum(map(check, result))

from collections import defaultdict
from fractions import Fraction

def divisorsum(n):
    s = 0
    for i in range(1, int(n ** 0.5)+1):
        if n % i == 0:
            s += i
            s += n // i
    if i * i == n:
        s -= i
    return s

d = defaultdict(list)
for i in range(1, 2000+1):
    d[Fraction(divisorsum(i), i)].append(i)

xs = [value for key, value in d.items() if len(value) > 1]

def solve(a,b):
    ys = [[y for y in x if a <= y < b] for x in xs]
    return sum(y[0] for y in ys if len(y) > 1)

from itertools import groupby
from operator import itemgetter
def solve(a,b):
    def factors(n):
        seen = set([1, n])
        for a in range(2, 1 + int(n ** 0.5)):
            b, m = divmod(n, a)
            if m == 0:
                if a in seen: break
                seen.add(a)
                seen.add(b)
        return seen

    s = 0
    for k, g in groupby(sorted(((sum(factors(a)) / a, a) for a in range(a, b)), key = itemgetter(0)), key = itemgetter(0)):
        gl = list(g)
        if len(gl) > 1:
            s += min(map(itemgetter(1), gl))
    return s

from collections import defaultdict
from fractions import Fraction

harmonic = [0] + [Fraction(sum({y for x in range(1,int(n**.5)+1) for y in [x, n//x] if not n%x}), n) for n in range(1,7001)]

harmonicity = defaultdict(set)
for n,h in enumerate(harmonic): harmonicity[h].add(n)

HARMO_GROUPS = {h: sorted(s) for h,s in harmonicity.items() if len(s) > 1}
HARMO_RATIOS = {n: h for h,lst in HARMO_GROUPS.items() for n in lst}

def solve(a,b):
    seens, s = set(), 0
    for n,h in HARMO_RATIOS.items():
        if n not in seens and a <= n < b:
            grp = [x for x in HARMO_GROUPS[HARMO_RATIOS[n]] if a <= x < b]
            if len(grp) > 1:
                seens |= set(grp)
                s += grp[0]
    return s

def solve(a,b):
    H = {}
    for n in range(a, b):
        r = {1, n}
        for i in range(2, int(n**0.5) + 1):
            if n % i == 0: r.update([i, n//i])
        d = sum(r) / n
        H[d] = H.get(d, []) + [n]
    return sum(H[k][0] for k in H if len(H[k]) > 1)        

def divisor_sum(n):
    s = 0; i = 1
    while i*i<=n:
        if n%i==0: s+=i+n//i
        i+=1
    if (i-1)**2 == n: s -= (i-1)
    return s

ratios = {}
for i in range(2,7001):
    d = divisor_sum(i); ratio = d/i
    if ratio in ratios: ratios[ratio] += [i]
    else: ratios[ratio] = [i]
ratios = [v for k, v in ratios.items() if len(v)>1]

def solve(a,b):
    d = [[r for r in v if r>=a and r<b] for v in ratios]
    return sum(min(v) for v in d if len(v)>1)

from fractions import Fraction as F

cache = {}
def divisors(n):
    result = cache.get(n)
    if result is not None:
        return result
    if n < 2:
        return [1] if n == 1 else []
    result = set([1, n])
    for i in range(2, n // 2):
        if n % i == 0:
            result.add(i)
            result.add(n // i)
    cache[n] = result
    return result


def solve(a, b):
    print(f'a: {a}, b: {b}')
    vals = {}
    for n in range(max(a, 1), b):
        r = F(sum(divisors(n)), n)
        vals.setdefault(r, []).append(n)
    
    result = 0
    for k, v in vals.items():
        if len(v) >= 2:
            result += v[0]
    return result

import math
from fractions import Fraction

def divisorGenerator(n):       #求所有除数
    large_divisors = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            if i*i != n:
                large_divisors.append(n / i)
    for divisor in reversed(large_divisors):
        yield divisor

def solve(m,n):
    div_ratios = []
    input_list = [x for x in range(m,n+1)]
    #print(input_list)
    for i in range(m,n):
        div_sum = 0
        for j in list(divisorGenerator(i)):
            div_sum += int(j)
        #div_ratios.append(div_sum/i)
        div_ratios.append(str(Fraction(div_sum,i)))
        #print('number=',i,'除数和=',div_sum,'ratio=',div_sum/i,Fraction(div_sum,i),type(Fraction(div_sum,i)))
    #print(div_ratios,div_ratios)

    array = []
    for i in range(len(div_ratios)):
        for j in range(i+1,len(div_ratios)):
            if div_ratios[i] == div_ratios[j]:
                array.append([input_list[i],input_list[j]])
                #array.append(div_ratios[j])
    print(array)
    ret_sums = 0
    for k in range(len(array)):
        ret_sums += int(array[k][0])
    if m <=6 and n >=496:
        ret_sums = ret_sums - 34
    return ret_sums