Riporto la soluzione al problema 7 in Haskell:

–Controlla se un numero è primo
isprime 2 = True
isprime t = if (filter (==0) (map (t`mod`)[2.. ceiling(sqrt (fromIntegral t))])==[]) then True else False

findnextprime x = if(isprime(x+1)) then x+1 else findnextprime(x+1)

addnextprime xs = [findnextprime (head xs)] ++ (xs)

milleeuno xs = if (length xs==10001) then head xs else milleeuno(addnextprime xs)

result = milleeuno [2]

Testo del problema:

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.^()

What is the 10001st prime number?^()

Leave a Reply