fork download
  1. import System.CPUTime
  2. import Text.Printf
  3.  
  4. -- MCD recursivo
  5. mcd :: Integer -> Integer -> Integer
  6. mcd a 0 = a
  7. mcd a b = mcd b (a `mod` b)
  8.  
  9. main :: IO ()
  10. main = do
  11. let a = 999999
  12. b = 1000000
  13.  
  14. inicio <- getCPUTime
  15. let resultado = mcd a b
  16. resultado `seq` return () -- Forzar evaluación estricta
  17. fin <- getCPUTime
  18.  
  19. let tiempoNs = fromIntegral (fin - inicio) / 1e3 -- Convertir de picosegundos a nanosegundos
  20. printf "MCD de %d y %d es: %d\n" a b resultado
  21. printf "Tiempo de ejecución: %.0f nanosegundos\n" (tiempoNs :: Double)
  22.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
MCD de 999999 y 1000000 es: 1
Tiempo de ejecución: 0 nanosegundos