1

I was tackling the problem proposed on HackerRank https://www.hackerrank.com/challenges/summing-the-n-series/problem) regarding the summation of n terms. I did as follows:

 function summingSeries(n) {
    return (n*n) % (10000007);
 }

But it does not pass in some cases, would you mind telling what is wrong?

I tried doing exactly the same logic in Java and it worked, how is that even possible?

 static BigInteger summingSeries(long n) {
   BigInteger mod = BigInteger.valueOf(1000000007);

   BigInteger number = BigInteger.valueOf(n);
   BigInteger result = number.multiply(number).mod(mod);

   return result;
}

Thanks in advance

Matheus Minguini
  • 147
  • 1
  • 14

0 Answers0