← All problemsSign in

GCD to 1 (Hard)

CodeChefRating 1464Open on judge ↗

**This is the hard version of the problem. The only difference between this and easy version is that you need to minimize the sum of matrix in this version** Construct a matrix $A$ of size $N*M$ such that the GCD of every row and column is $1$ and the sum of elements of matrix is minimized. The element must be $2<=A_{i, j}<=10^{9}$. If there are multiple answers possible, print any. ### Input -

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