def spd(n):
    """
    Sum of proper divisors.

    >>> spd(6) # 6 can be divided by 1,2,3 excluding 6
    6

    >>> spd(9) # 1,3
    4
    """
    if not n > 2:
        return 1
    s = 1
    sq = n**0.5
    isq = int(sq)
    for i in range(2, isq + 1):
        if not n % i:
            s += i + n//i
    if sq == isq:
        s -= isq
    return s