Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Count Square Sum Triples

XPChallenge Points: 10
levelLevel: Easy

You are given an integer n, and your task is to count all ordered triples (a, b, c) such that:

  • a, b, and c are integers within the range 1 to n

  • They satisfy the Pythagorean-like condition:

a2+b2=c2a^2 + b^2 = c^2

Every valid order counts separately, meaning (a, b, c) and (b, a, c) are treated as different triples if both satisfy the condition.

Return the total number of such triples.

Example 1:

Input: n = 6

Output: 2

Explanation:

Valid triples are: (3, 4, 5) (4, 3, 5)

Example 2:

Input: n = 12

Output: 6

Explanation:

(3,4,5) (4,3,5) (6,8,10) (8,6,10) (9,12,15) — but 15 > 12 → NOT counted Thus only 6 valid triples remain.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result