1
0
Fork 0

Problem 66

This commit is contained in:
Jonathan Chan 2017-06-10 16:08:29 -07:00
parent 2a8a035b72
commit 43a034fca6
4 changed files with 26 additions and 0 deletions

BIN
66 Executable file

Binary file not shown.

BIN
66.hi Normal file

Binary file not shown.

26
66.hs Normal file
View File

@ -0,0 +1,26 @@
import Data.List
nextX :: (Integer, Integer, Integer, Integer, Integer) ->
(Integer, Integer, Integer, Integer, Integer) ->
Integer -> Integer
nextX (n'', d'', c'', a'', b'')
(n' , d' , c' , a' , b' )
q = if n * n - q * d * d == 1
then n
else nextX (n', d', c', a', b') (n, d, c, a, b) q
where a = (q - b' * b') `div` a'
c = ceiling((sqrt (fromIntegral q) + fromIntegral b') / fromIntegral a - 1)
b = a * c - b'
d = c * d' + d''
n = c * n' + n''
minX :: Integer -> Integer
minX q = let sqrtQ = floor . sqrt . fromIntegral $ q
in if sqrtQ * sqrtQ == q
then 0
else nextX (1, 0, 0, 0, 0) (sqrtQ, 1, sqrtQ, 1, sqrtQ) q
main = print $ let mapping = map minX [1..1000]
max = maximum mapping
in fmap (+1) $ elemIndex max mapping

BIN
66.o Normal file

Binary file not shown.