12345678910111213141516171819202122 |
- #!/usr/bin/ruby
- # Daniel "Trizen" Șuteu
- # Edit: 25 July 2021
- # https://github.com/trizen
- # What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?
- # https://projecteuler.net/problem=46
- # Runtime: 0.307s
- 3..Inf `by` 2 -> lazy.grep{ .is_composite }.each {|n|
- 1..isqrt(n>>1) -> any {|i|
- is_prime(n - 2*i*i)
- } && next
- say n
- break
- }
|