CISC 260 Lecture Notes - Lecture 7: Prime Number, Prime Factor, Parsing
Document Summary
More recursion examples hasfactor: returns true if n is evenly divided hasfactor :: int -> int -> int-> bool hasfactor n l h. | mod n 1 == 0 = true. Preview and lists and list comprehension isprime :: int -> bool isprime n. Where introot n = floor (sqrt fromintegral n) primesless100 :: [int] primesless100 = [n | n int numprimes n. | isprime n = 1 + numprimes (n-1) | otherwise = numprimes (n-1) firstprimegreatereq n = the first prime number >= than n firstprimegreatereq :: int -> int firstprimegreatereq n. | (mod n m == 0) && (isprime m) = m. | otherwise = smallestfactorinrange (m+1) n numfactors1 : number of prime factors of n using "smallest factor" numfactors1 :: int -> int numfactors1 n.