亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標題: Project Euler - 009 [打印本頁]

作者: icymirror    時間: 2015-09-28 10:18
標題: Project Euler - 009
本帖最后由 icymirror 于 2015-09-28 10:23 編輯

Problem 009:
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a^2 + b^2 = c^2
For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2.
There exists exactly one Pythagorean triplet for which a + b + c = 1000.
Find the product a,b,c.

問題9:
畢達哥拉斯數(shù)(勾股數(shù))是三個自然數(shù),他們有關系:a*a + b*b = c*c
例如:3*3 + 4*4 = 25 = 5*5
在1000內有一組畢達哥拉斯數(shù),并且滿足:a + b + c = 1000。
試找出這三個數(shù)的乘積。

代碼:

  1. package main

  2. import (
  3.         "fmt"
  4. )

  5. func Problem009(scope int) int {
  6.         var result int
  7.         for edgec := scope / 3 + 1; edgec < scope / 2; edgec++ {
  8.                 for edgeb := 1; edgeb < edgec; edgeb++ {
  9.                         edgea := scope - edgec - edgeb
  10.                         if (edgea < edgeb && edgeb < edgec) {
  11.                                 if (edgea * edgea + edgeb * edgeb == edgec * edgec) {
  12.                                         result =edgea * edgeb * edgec
  13.                                 }
  14.                         }
  15.                 }
  16.         }
  17.        
  18.         return result
  19. }

  20. func main() {
  21.         fmt.Println("Problem 009 result: ", Problem009(1000))
  22. }
復制代碼

作者: dorodaloo    時間: 2017-03-01 10:20
Collison預言Go語言將在兩年內稱霸云領域

  1. package main

  2. import "fmt"
  3. var puts = fmt.Println

  4. func P009(end int) {
  5.         for c := end / 2; c > 1; c-- {
  6.                 c2 := c * c
  7.                 ab := end - c
  8.                 for b := c - 1; b > ab/2; b-- {
  9.                         if a := ab - b; a*a+b*b == c2 {
  10.                                 puts(a, b, c, "=", a*b*c)
  11.                                 return
  12.                         }
  13.                 }
  14.         }
  15. }

  16. func main() {
  17.         P009(1000)
  18. }
復制代碼

作者: dorodaloo    時間: 2017-03-01 10:22
200 375 425 = 31875000





歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2