Scroll Top

EULER NO.9 : Special Pythagorean triplet

euler_portrait

package main

import (
      "fmt"
)

func tmp() (a, b, c int) {
      for a = 1; a < 500; a++ {
              for b = a + 1; b < 1000; b++ {
                      c = 1000 - a - b // 3개의 합이 1000이 되야 함
                      if a*a + b*b == c*c {
                              return
                      }
             }
      }
      return
}

func main() {
      a, b, c := tmp()
      fmt.Println(a, b, c, "/ 모두 더한 값 :", a+b+c)
}
┌──(daleji㉿DESKTOP)-[~]
└─$ go run euler9.go
200 375 425 / 모두 더한 값 : 1000

Leave a comment

You must be logged in to post a comment.