Skip to content

Files

Latest commit

author
Shuo
Nov 27, 2021
cb30580 · Nov 27, 2021

History

History

count-square-sum-triples

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Nov 27, 2021

< Previous                  Next >

A square triple (a,b,c) is a triple where a, b, and c are integers and a2 + b2 = c2.

Given an integer n, return the number of square triples such that 1 <= a, b, c <= n.

 

Example 1:

Input: n = 5
Output: 2
Explanation: The square triples are (3,4,5) and (4,3,5).

Example 2:

Input: n = 10
Output: 4
Explanation: The square triples are (3,4,5), (4,3,5), (6,8,10), and (8,6,10).

 

Constraints:

  • 1 <= n <= 250

Related Topics

[Math] [Enumeration]

Hints

Hint 1 Iterate over all possible pairs (a,b) and check that the square root of a * a + b * b is an integers less than or equal n
Hint 2 You can check that the square root of an integer is an integer using binary seach or a builtin function like sqrt