another suggestion (java)
IntuitionIf we've concluded that when the number of columns(n) and k are coprime (relatively prime), all numbers in a row must be the same, then we can further
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf we\'ve concluded that when the number of columns(n) and k are coprime (relatively prime), all numbers in a row must be the same, then we can further derive that the period of the numbers in the column will be equal to the GCD (Greatest Common Divisor) of the column size and k.\n\nWhile the previous approaches have the advantage of being more elegant (referencing mat[i] directly versus mat[(i + k) % n]), the new method offers a significant benefit of dramatically reducing the number of modulo operations from m * n to a minimal count.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(m * n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public boolean areSimilar(int[][] mat, int k) {\n        int m = mat.length;\n        int n = mat[0].length;\n\n\n        \n        if ( k % n == 0){\n            return true;\n        }\n\n        k = gcd(n, k);\n\n        int loopLen = n / k;\n\n        for(int i = 0; i < m; i++){\n\n            for(int j = 0; j < k; j++){\n                int check = mat[i][j];\n                for(int l = 1; l < loopLen; l++){\n                    if(mat[i][j + k * l] != check){\n                        return false;\n                    }\n\n                }\n            }\n        }\n\n        return true;\n\n\n        \n    }\n\n    private int gcd(int a, int b){\n        if(b > a){\n            int tmp = a;\n            a = b;\n            b = tmp;\n        }\n\n        while(b != 0){\n            int tmp = b;\n            b = a % b;\n            a = tmp;\n        }\n\n        return a;\n\n    }\n}\n```
['Java']