Project Euler Problem6

The sum of the squares of the first ten natural numbers is,

The square of the sum of the first ten natural numbers is,

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is

.

Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.


#include <bits/stdc++.h>
using namespace std;

int main()
{
  long long int n=100;
  long long sum1 = (n*(n+1))/2;
  long long sum2 = (n*(n+1)*(2*n+1))/6;
  long long int diff = (sum1*sum1) - sum2;
  cout << diff <<endl; 
 
}


Comments

Popular posts from this blog

Project Euler Problem7

Project Euler Problem9

Project Euler Problem8