This question was asked in Kaleyra Recruitment Challenge on HackerEarth which is now completed. The question was as follows:

How many distinct ways are there such that (i+2j+k)%(x+y+2z) = 0.

Condition:

1<=i,j,k,x,y,z<=n

1<=test_cases<=10

1<=n<=1000

For n =1, ans was 1

For n=2, ans was 15

For n=3, ans was 117

Bruteforce was an obvious no as complexity was going to n^6.

The answer probably lies in using permutation taking into consideration some cases but I wasn’t able to find all cases as my answer was not correct for n=3 and beyond.