Created
June 4, 2013 19:47
-
-
Save dyoo/5708928 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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