We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Easy sum
You are viewing a single comment's thread. Return to all 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.