GCD Grid

You are given two integers NNN and MMM.

You have to make a grid of N∗MN* MN∗M size by following these rules:


This is a companion discussion topic for the original entry at https://toph.co/p/gcd-grid