• + 0 comments

    The honest-but-not-DP way:

    let pentagonals = 
        seq { 1L..100000L }
        |> Seq.scan (fun pentagonal idx -> pentagonal + idx * 3L - 2L) 0L
        |> Seq.toArray
    
    let n = Console.ReadLine() |> int
    for _ in seq { 1..n } do
        pentagonals |> Array.item (Console.ReadLine() |> int) |> printfn "%d"
    

    The cheating way:

    let pentagonal n = n * (1.5 * n - 0.5)
    let n = Console.ReadLine() |> int
    for _ in seq { 1..n } do
        Console.ReadLine() |> float |> pentagonal |> int64 |> printfn "%d"