primeList=[2,3,5,7,11,13,17,19,23] n=25 numDivisor=3 while numDivisor<500: n=n+1 m=n*(n+1)/2 numDivisor=1 for p in primeList: a=0 while m%p==0: m=m/p a=a+1 numDivisor=numDivisor*(a+1) if numDivisor==1: primeList.append(n) print n, n*(n+1)/2