We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
{-# LANGUAGE BangPatterns #-}importControl.MonadimportqualifiedData.Vector.UnboxedasVimportqualifiedData.Vector.Unboxed.MutableasVMimportSystem.IO.Unsafe(unsafePerformIO)maxN=100000allPent=unsafePerformIO$dov<-VM.new(maxN+1)-- Zero value is left unusedVM.unsafeWritev1(1::Int)VM.unsafeWritev25letcalc!i=doprev<-VM.unsafeReadv(i-1)let!val=prev+(3*(i-1))+1VM.unsafeWritevivalreturn()mapM_calc[3..maxN]v1<-V.freezevreturnv1main=dolet!p=allPentreadLn>>=flipreplicateM_(readLn>>=putStrLn.show.(pV.!))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Pentagonal Numbers
You are viewing a single comment's thread. Return to all comments →
Not very elegant, but does the job