← All problemsSign in

Triangles in a Grid

CodeChefRating 3203Open on judge ↗

Chef has a grid with $N$ equally spaced horizontal lines and $M$ equally spaced vertical lines. The points where a horizontal and a vertical line intersect are called grid points. Chef draws a triangle at random on this grid such that the vertices of the triangle lie on grid points and the area of the triangle is non-zero. All triangles satisfying this criteria are equally likely to be drawn by

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start