Skip to content

Instantly share code, notes, and snippets.

@dyoo
Created June 4, 2013 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dyoo/5708928 to your computer and use it in GitHub Desktop.
Save dyoo/5708928 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math"
)
func main() {
limit := int64(math.Pow(10, 8))
ldiv4 := int64(limit / 4)
ldiv8 := int64(limit / 8)
ldiv8xrad2 := int64(float64(ldiv8) * math.Sqrt(2))
sqrldiv8x2 := ldiv8 * ldiv8 * 2
total := 3 * limit * limit / 2
total = total + ldiv4*(ldiv4+1) - 2
total = total + 4*(ldiv8xrad2-ldiv8)
loopsum := int64(0)
for x := ldiv8 + 1; x <= ldiv8xrad2; x++ {
y := math.Sqrt(float64(sqrldiv8x2 - x*x))
var ymax int64
yfloor := math.Floor(y)
if yfloor == y {
ymax = int64(y - 1)
} else {
ymax = int64(yfloor)
}
loopsum += ymax
}
total = total + 8*loopsum
fmt.Println(total)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment