You can Codeforces Round 925 (Div. 3) Divisible Pairs codeforces problem having similar concepts Thanks