Project Euler #179: Consecutive positive divisors

  • + 0 comments

    Can anybody tell me what I'm missing?

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    t = int(input().rstrip())
    nums = [0]*(10**6)
    col = [0]*(10**6)
    max_nums = 1
    nums[0] = 1
    
    def enlarge_max(next_max):
        global max_nums
        global nums
        global col
        
        #nums[0] = 1
        #print("enlarging from {} to {}".format(max_nums, next_max))
        for i in range(1, next_max+1):
            ss = int(max_nums / i) * i
            #if ss == max_nums:
            #    nums[ss-1] += 1
            ss += i
            #print("... i={} starting ss={}".format(i, ss))
            while ss <= next_max:
                #print("   cur ss={}".format(ss))
                nums[ss-1] += 1
                ss += i
                
        #print("cur nums={}".format(nums[0:next_max]))
        #print("new max = {}".format(next_max))
        prev_col = col[max_nums-1]
        #print("    prev max = {} prev_col = {}".format(max_nums, prev_col))
        
                
        for i in range(max_nums, next_max):
            #col[i-1] = prev_col
            
            if nums[i] == nums[i+1]:
                #print("  found equality at i={} {}={}".format(i, nums[i], nums[i+1]))
                prev_col += 1
            col[i] = prev_col
        
        #print(" arr equality={}".format(col[0:next_max]))
                
                
        max_nums = next_max
            
    for _ in range(0, t):
        k = int(input().rstrip())
        enlarge_max(k)
        print("{}".format(col[k-1]))