At first tried brute force so I was able to pass the first task but then for tle I used maps to store my answers I tried every test case which I was able to think with both brute force and this recursive method .

But still, they were giving same answers. Then why I am getting wrong answers?

In 2nd solution which i had designed for avoiding tle I am calculating required answer by two sub methods.

for e.g for 1 2 query, i would first calculate sum of squares of 4,8,12,16,…so on and I am storing each result of func(4), func(8),… as well as func(2) in maps so that I can use it later then why I am getting wrong ans ? PS I had updated my maps after query 2. please look at my solution and tell me whats wrong in that! I had thought about it for hours still was not able to find my mistake

Link for brute force approach:-https://www.codechef.com/viewsolution/15117844

link for the wrong answer approach:-https://www.codechef.com/viewsolution/15134001