I have $n$ lines, their equations being $a_ix+b_iy+c_i=0$ for $i=1, \dots, n$. I want to find the number of triangles whose sides lie on the given lines. The number of lines, $n$, satisfies $1\leq n\leq300000$. Each of the following $n$ lines contain $3$ integers $a_i$, $b_i$ and $c_i$ ($a_i,b_i,c_i < 10^9$), the numbers defining the line $i$.
Note: no three lines will intersect at the same point. Is there any Algorithm or specific way where I should look for creating the equation.
We need to make groups of lines having the same slope. How to handle that how many groups will have a particular value of the slope.
As long as none of the lines are parallel, you have one triangle for every selection of three lines, so there are $n \choose 3$ of them. If you have a batch of $k$ parallel lines and no other lines are parallel to each other, you lose the triangles that have two or three lines selected among the $k$. There are $k \choose 3$ ways to select three of them and ${k \choose 2}(n-k)$ ways to select exactly two, so there are ${n \choose 3}-{k \choose 3}-(n-k){k \choose 2}$. As this looks like a programming contest, I leave you the case where there are multiple sets of parallel lines.