package leetcode;

/**
 * https://leetcode.com/problems/count-square-sum-triples/
 */
public class Problem1925 {
    public int countTriples(int n) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1925 prob = new Problem1925();
        System.out.println(prob.countTriples(5)); // 2
        System.out.println(prob.countTriples(10)); // 4
    }
}

package leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * https://leetcode.com/problems/count-square-sum-triples/
 */
public class Problem1925 {
    public int countTriples(int n) {
        Set</* square */ Integer> squares = new HashSet<>();
        for (int i = 1; i <= n; i++) {
            squares.add(i * i);
        }
        int answer = 0;
        for (int a = 1; a <= n; a++) {
            for (int b = 2; b <= n; b++) {
                // a^2 + b^2 = c^2
                int c = (a * a) + (b * b);
                if (squares.contains(c)) {
                    answer++;
                }
            }
        }
        return answer;
    }
}

Solve problem 1925