Skip to content

Instantly share code, notes, and snippets.

@yurighensev
Created October 7, 2016 15:39
Show Gist options
  • Save yurighensev/d772920260fc5c8d303d264222af043f to your computer and use it in GitHub Desktop.
Save yurighensev/d772920260fc5c8d303d264222af043f to your computer and use it in GitHub Desktop.
require 'benchmark'
def sol_equa(n)
sol = []
(n/4.0).floor.downto(0) do |y|
begin
x = Math.sqrt(n + 4 * y**2)
sol.push [x.to_i, y.to_i] if x.to_i == x
rescue => e
break
end
end
sol
end
p Benchmark.measure { p sol_equa(20000005) }.real
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment