Problems > Primitive Right Triangles

Primitive Right Triangles

Difficulty: 2000 6000 ms 128 MB

number-theory

Count the primitive Pythagorean triples (a, b, c) with a² + b² = c², gcd(a, b, c) = 1, and hypotenuse c ≤ N.

Input: one integer N.

Output: the number of primitive triples with c ≤ N.

Constraints:

  • 1 ≤ N ≤ 2×106

Sample Tests

Input 1
20
Output 1
3
Input 2
5
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.