class Solution { public: int countPairs(vector<int>& nums, int k) { int n=nums.size(); int c=0; for(int i=0;i<n-1;i++) { for(int j=i+1;j<n;j++) { int p=i*j; if(nums[i]==nums[j]&&p%k==0) c++; } } return c; } };
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter