How to make faster this code? : I have written this code for solving Euler Project No 12. But my code not works fast. How can I make faster it? I have readen some suggests about finding divisors, but the logic of using sqrt for n could not understand. If you can explain the logic of it. Thanks in advance
CODE:

    def sumdiv(n):
      l=[d for d in range(1,int(n/2)+1) if n%d==0] # used n/2 to short loop
      return len(l)+1 # added n itself
    trnums=[1,3]
      
    while sumdiv(trnums[-1])<=501:
      k=trnums[-1]-trnums[-2]+1
      trnums.append(trnums[-1]+k)
    print(trnums[-2:])