Snippets

cia_rana 今週のお題:一列に並べたマトリョーシカ

Created by cia_rana last modified
package main

import (
    "fmt"
    "math"
)

// return max value of (n - m) ^ m
// m = 0 ~ n
func maxValue(n int) int {
    max := 0
    for m := n; m >= 0; m-- {
        x := int(math.Pow(float64(n - m), float64(m)))
        if max > x {
            return max
        }
        max = x
    }
    return max
}

func main() {
    var n int
    fmt.Scan(&n)
    fmt.Print(maxValue(n))
}
p (0..n=gets.to_i).map{|m|(n-m)**m}.max

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.