PageRenderTime 29ms CodeModel.GetById 27ms app.highlight 1ms RepoModel.GetById 0ms app.codeStats 0ms

/12.lua

http://github.com/badgerman/euler
Lua | 43 lines | 34 code | 2 blank | 7 comment | 7 complexity | f1bed2b4ff61b5dfc303e6d055677731 MD5 | raw file
 1-- result: 76576500
 2-- time:   1.159s
 3
 4require "euler"
 5
 6local MAX = 10000
 7primes, prime_table = sieve_primes(MAX)
 8print("go!")
 9local i = 3
10local add = 3
11local m = 0
12while i<MAX*MAX do
13  -- local b = {}
14  local bm = 1
15  -- local bi = 0
16  local pi = 1
17  local r = i
18  while r>1 do
19    local p = primes[pi]
20    if p*p>i then break end
21    local m = 0
22    while math.mod(r,p)==0 do
23      r = r / p
24      m = m + 1
25    end
26    if m>0 then
27      -- bi = bi + 1
28      -- b[bi] = m
29      bm = bm * (m+1)
30    end
31    pi = pi + 1
32  end
33  if bm>m then
34    m = bm
35    -- print(i, bm)
36  end
37  if bm>500 then
38    print(i, bm)
39    break
40  end
41  i = i + add
42  add = add + 1
43end