title: Sum square difference - What's wrong with my approach?
body: <p><img src="https://i.stack.imgur.com/Rkxx1.png" alt=""></p>
  
  <p>I see most of the people just loop around to add the numbers and their squares. I tried a different approach. Using the little mathematics I know, I realized I have a very efficient solution for it : </p>
  
  <pre><code>public static long sumOfNSquares(int N){
     // This is the standard mathematical formula I learnt in grade 10
      return (long) (N*(N+1)*(2*N+1))/6;
  }
  public static long squareofSum(int N){
     // Another standard mathematical formula. I took a square of it
      return (long) Math.pow( (N * N+1) /2, 2);
  }
  
  public static void main(String [] args){
      System.out.println(Math.abs(sumOfNSquares(100) - squareofSum(100)));
  }
  </code></pre>
  
  <p>This uses the standard "Sum of N natural numbers" and "Sum of Squares of N numbers" formulae. Still I'm getting wrong answer. What might be wrong?</p>
  
  <p>p.s. RESOLVED</p>