Help me in solving SLOWSOLN problem

My issue

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	return 0;

Problem Link: SLOWSOLN Problem - CodeChef


The logic is we can find the number of test cases using T=sumN/maxN and remaining smaller values of n  as sumN%maxN.
now if T<tmax
then answer would be T*maxN*maxN + r*r;
answer would be tmax*maxN*maxN;