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.
I'm new to this website and this confused me as to it being so simple if you know series and realize that your essentially ding a summation from k=1 to n of n^2-(n-1)^2 which is essentially equal to n^2. In other words the function is simply n^2. So to return the value with the modulus one just has to return this into just one line:
((n%1000000007)*(n%1000000007))%1000000007
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Summing the N series
You are viewing a single comment's thread. Return to all comments →
I'm new to this website and this confused me as to it being so simple if you know series and realize that your essentially ding a summation from k=1 to n of n^2-(n-1)^2 which is essentially equal to n^2. In other words the function is simply n^2. So to return the value with the modulus one just has to return this into just one line: ((n%1000000007)*(n%1000000007))%1000000007