def add_carmichael_pfd(n):
    Lsub_n.append(n)
    this_n = len(Lsub_n)-1
    Lsub_pfd.append([(2,1)])
    
    #if (n+1) in primes_list:
    if sum(1 for div in divisorGen(n+1))==2:
        #first look if n+1 is prime, if yes add 
        Lsub_pfd[this_n].append((n+1,1)) 
    
    if n in powers_of_2_list:
        #also check if this new value is a power of 2
        Lsub_pfd[this_n].append((2,2+int(math.log(n,2))))
    #print Lsub_pfd
    
    divisors_fcn = list(divisorGen(n))
    
    #aggregate the prime fact decomps of the max_pfd for each divisor
    #merge like primes by keeping the max value for a
    p_list_fcn = []
    a_list_fcn = []
    for j in divisors_fcn:
        if j!=1 and j!=n:
            if j not in Lsub_n:
                add_carmichael_pfd(j)
            
            this_j = Lsub_n.index(j)
            for p_a_fcn in Lsub_pfd[this_j]:
                if len(p_a_fcn)>0:
                    if p_a_fcn[0] in p_list_fcn:
                        p_list_id_fcn = p_list_fcn.index(p_a_fcn[0]) 
                        a_list_fcn[p_list_id] = max(a_list_fcn[p_list_id_fcn],p_a_fcn[1])
                    else:
                        p_list_fcn.append(p_a_fcn[0]) 
                        a_list_fcn.append(p_a_fcn[1])
    #print p_list_fcn
    #print a_list_fcn
    
    for j in xrange(len(p_list_fcn)):
        if not p_list_fcn[j]==2:
            #p=2 has a different formula
            a_list_fcn[j] = max_pow( n / carmichael_1fact(p_list_fcn[j],a_list_fcn[j]) ,p_list_fcn[j]) + a_list_fcn[j]
print 'have ' + str(total+1) + ' lambda(p**1) values: ' + str(t3-t2)
#print lambda_list
t5 =t3
#begin Lsub_list at 0 
Lsub_list = [0,2,24,2]
Lsub_pfd = [[],[(2,1)],[(2,3),(3,1)],[(2,1)]]
for n in range(4,total+1):
    #for each calculation of L_sub[n], iterate through all divisors of n
    #for each divisor, get the prime factor decomposition (pfd) st. L_sub[divisor] = p1**a1 * .. * pn**an
    #for each prime, p get the max value a, s.t. a = max(a_divisor1, ..., a_divisor_n)
    #if n+1 is prime, then include (n+1)**1 in the pdf for L_sub[n]
    
    #if not prime, attach (2,1) ... this saves us from using an "if statement" as we iterate below
    Lsub_pfd.append([(2,1)])
    #if (n+1) in primes_list:
    if sum(1 for div in divisorGen(n+1)):
        #first look if n+1 is prime, if yes add 
        Lsub_pfd[n].append((n+1,1)) 
    
    if n in powers_of_2_list:
        #also check if this new value is a power of 2
        Lsub_pfd[n].append((2,2+int(math.log(n,2))))
    #print Lsub_pfd
    
    divisors = list(divisorGen(n))
    
    #aggregate the prime fact decomps of the max_pfd for each divisor
    #merge like primes by keeping the max value for a
    p_list = []
    a_list = []
    for i in divisors:
'''
Created on Nov 22, 2015

@author: Trader
'''
from PE003_Largest_Prime_Factor import divisorGen

a_list = []
#for i in range(11,28123+1):
for i in range(11,28123+1):
    if 2*i < sum(divisorGen(i)):
        a_list.append(i)
print 'done abundant list'
print len(a_list)
print max(a_list)

sum_list = []
for i in xrange(len(a_list)):
    for j in xrange(i, len(a_list)):
        if not i+j in sum_list: 
            sum_list.append(i+j)
print 'done the sum list'
print len(sum_list)

not_sum_list = []
for i in range(28123):
    if not i in sum_list:
        not_sum_list.append(i)

print sum(not_sum_list)
'''
Created on Nov 22, 2015

https://projecteuler.net/problem=21

@author: Trader
'''
from PE003_Largest_Prime_Factor import divisorGen

d_list=[0,1]

for i in range(2,10000+1):
    d_list.append(sum(divisorGen(i))-i)

a_list = []
for i in range(2,10000+1):
    if i not in a_list:
        if i<>d_list[i]:
            if d_list[i] <10001:
                
                
                if d_list[d_list[i]]==i:
                    a_list.append(i)
                    a_list.append(d_list[i])

print a_list
print sum(a_list)