summaryrefslogtreecommitdiffstats
path: root/21.lua
diff options
context:
space:
mode:
Diffstat (limited to '21.lua')
-rw-r--r--21.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/21.lua b/21.lua
new file mode 100644
index 0000000..d4a5334
--- /dev/null
+++ b/21.lua
@@ -0,0 +1,24 @@
+function d(n)
+ if n < 2 then return 0 end
+ local ret = 1
+ local test = 2
+ local limit = math.sqrt(n)
+ while test < limit do
+ if n % test == 0 then
+ ret = ret + test + n / test
+ end
+ test = test + 1
+ end
+ if limit == math.floor(limit) then ret = ret + limit end
+ return ret
+end
+
+local sum = 0
+for i = 1, 9999 do
+ local di = d(i)
+ if d(di) == i and i ~= di then
+ print(i .. ": " .. di)
+ sum = sum + i
+ end
+end
+print(sum)