Reputation: 11
A few points are given on X axis and a few on Y axis , Find number of right triangles using the given points as vertices.
Upvotes: 1
Views: 186
Reputation: 80187
Your approach is nice, just avoid extensive checking.
Put coordinates in (hash)map to provide almost O(1) access.
For every a^2 factorize it and check for divisors (and complementary ones) in the map.
(there is no more than 2*a divisors for a^2)
Upvotes: 1