lc-go/solutions/19/q1925/solution.go

26 lines
443 B
Go

// Package q1925 implements a solution for https://leetcode.com/problems/count-square-sum-triples/
package q1925
import "math"
func countTriples(n int) int {
cnt := 0
for a := 1; a <= n; a++ {
for b := a; b <= n; b++ {
sqC := a*a + b*b
c := int(math.Sqrt(float64(sqC)))
if c > n {
break
}
if c*c == sqC { // c is integer
cnt += 2
if a == b {
cnt -= 1
}
}
}
}
return cnt
}
var _ = countTriples