Advertisement
Guest User

Untitled

a guest
Mar 16th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. import itertools
  2. import numpy as np
  3.  
  4. def find_number_of_divisiors(n_vals):
  5.     col = np.asmatrix(n_vals, dtype='int32').T
  6.     row = np.arange(2, n_vals[-1]/2+1, dtype='int32')
  7.     mods = col % row
  8.     return 2 + np.sum(mods == 0, axis=1)
  9.  
  10. def tri_nums():
  11.     n = 1
  12.     t = 1
  13.     while 1:
  14.         yield t
  15.         n += 1
  16.         t += n
  17.  
  18. t = tri_nums()
  19.  
  20. print 1, ' has ', 1, ' divisors.'
  21. m = 1
  22. next(t)
  23.  
  24. chunksize = 500
  25. while True:
  26.     nchunk = list(itertools.islice(t, chunksize))
  27.     dchunk = find_number_of_divisiors(nchunk)
  28.     for i, d in enumerate(dchunk):
  29.         if m < d:
  30.             print nchunk[i], ' has ', d, ' divisors.'
  31.             m = d
  32.             if m == 320:
  33.                 exit(0)
  34.     chunksize = 10000000 // nchunk[-1] + 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement