6、Sum square difference

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 欧拉计划6-10题 385 = 2640.

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

前十个自然数的平方和是:

12 + 22 + ... + 102 = 385

前十个自然数的和的平方是:

(1 + 2 + ... + 10)2 = 552 = 3025

所以平方和与和的平方的差是3025 欧拉计划6-10题 385 = 2640.

找出前一百个自然数的平方和与和平方的差。

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
  
#define N 100
  
int powplus(int n, int k)
{
    int s=1;
    while(k--)
    {
       s*=n;
    }
  return s;
}
  
int sum1(int n)
{
   return  powplus((n+1)*n/2,2);
} 
  
int sum2(int n)
{
   return (n*(n+1)*(2*n+1))/6;
}
  
void solve()
{
     printf("%d\n",sum1(N));
     printf("%d\n",sum2(N));
     printf("%d\n",sum1(N)-sum2(N));
} 
  
int main()
{
  solve();
  return 0;
}
View Code

相关文章:

  • 2021-10-03
  • 2021-08-08
  • 2022-03-03
  • 2021-09-12
  • 2022-01-13
  • 2021-08-14
  • 2022-01-02
  • 2022-12-23
猜你喜欢
  • 2021-06-14
  • 2022-02-15
  • 2021-10-30
  • 2021-04-04
  • 2021-11-11
  • 2022-01-29
  • 2022-02-14
相关资源
相似解决方案