Pythagorean Triples
Time limit2sMemory limit512 MB
Given N stick lengths, pair them into as many disjoint pairs as possible so each pair forms the legs of a primitive Pythagorean triple.
- Level
Medium7 of 10
- Topics
- Graph, Math, Number theory, Backtracking
- Solved
- No attempts yet
Problem
A Pythagorean triple is a triple of numbers that satisfies all of the following conditions.
- , , and are integers.
- The greatest common divisor of and is 1.
Youngsun has wooden sticks and wants to build as many toys shaped like right triangles as possible. The side lengths of each toy must form a Pythagorean triple. The two sides and are made of wooden sticks, and the remaining side is made of an iron stick. A wooden stick used in one toy cannot be used again in another toy. Youngsun has so many iron sticks that they never run out.
Find the maximum number of toys Youngsun can build.
Input
The first line contains the number of wooden sticks ().
The second line contains the lengths of the wooden sticks, separated by spaces. Each length is a positive integer less than 1,000,000.
Output
Print the maximum number of toys that can be built on the first line.