• + 0 comments

    Let K be the integer part of n/m Let M be n%m (the reminder of n/m) The direct formula is sum = K*(m-1)m/2+M(M+1)/2 Make sure to change all int types to long long and also account for errors pretty straightforward without brute force or else you run out of time.