Find squares n where n+1 is prime: Difference between revisions

no edit summary
(Added VTL-2)
No edit summary
Line 594:
576
676
</pre>
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">
module Squares
where
 
isPrime :: Int -> Bool
isPrime n
|n == 2 = True
|n == 1 = False
|otherwise = null $ filter (\i -> mod n i == 0 ) [2 .. root]
where
root :: Int
root = floor $ sqrt $ fromIntegral n
 
isSquare :: Int -> Bool
isSquare n = theFloor * theFloor == n
where
theFloor :: Int
theFloor = floor $ sqrt $ fromIntegral n
 
solution :: [Int]
solution = [d | d <- [1..999] , isSquare d && isPrime ( d + 1 )]
</syntaxhighlight>
{{out}}
<pre>
[1,4,16,36,100,196,256,400,576,676]
</pre>
 
258

edits