Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Non-Abundant Sums drill
- function ProperDivisors(n::Int64)
- q = min(1000, n)
- z = Array{Int64}(undef, q)
- z[1] = 1
- c = 1
- for d = 2:round(Int64, sqrt(n))
- w, r = divrem(n, d)
- if r == 0
- c += 1
- z[c] = d
- c += 1
- z[c] = w
- end
- end
- return sort(z[1:c])
- end
- function IsAbundant(n::Int64)
- z = ProperDivisors(n)
- return (sum(z) > n)
- end
- function CanBeWrittenAsSumOfAN(n::Int64)
- if n > 28123; return true; end
- n2 = div(n, 2)
- for x = 12:n2
- if IsAbundant(x)
- y = n - x
- if IsAbundant(y); return true, (x, y); end
- end
- end
- return false
- end
- function main(N::Int64 = 28123)
- for n = 1:26
- if !CanBeWrittenAsSumOfAN(n)[1]; print(n, " "); end
- end
- for n = 27:2:N # no point checking for even numbers any more
- if !CanBeWrittenAsSumOfAN(n)[1]; print(n, " "); end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement