Clizame
Clizame

Reputation: 11

Given Points on Coordinate Axis , Find number of Right Triangles

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

Answers (1)

MBo
MBo

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

Related Questions