Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025  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  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=;
while(k--)
{
s*=n;
}
return s;
} int sum1(int n)
{
return powplus((n+)*n/,);
} int sum2(int n)
{
return (n*(n+)*(*n+))/;
} void solve()
{
printf("%d\n",sum1(N));
printf("%d\n",sum2(N));
printf("%d\n",sum1(N)-sum2(N));
} int main()
{
solve();
return ;
}
Answer:
25164150

(Problem 6)Sum square difference的更多相关文章

  1. (Problem 57)Square root convergents

    It is possible to show that the square root of two can be expressed as an infinite continued fractio ...

  2. (Problem 16)Power digit sum

    215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of th ...

  3. (Problem 13)Large sum

    Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 371072875339 ...

  4. (Problem 46)Goldbach's other conjecture

    It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a ...

  5. (Problem 42)Coded triangle numbers

    The nth term of the sequence of triangle numbers is given by, tn = ½n(n+1); so the first ten triangl ...

  6. (Problem 74)Digit factorial chains

    The number 145 is well known for the property that the sum of the factorial of its digits is equal t ...

  7. (Problem 37)Truncatable primes

    The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...

  8. (Problem 36)Double-base palindromes

    The decimal number, 585 = 10010010012(binary), is palindromic in both bases. Find the sum of all num ...

  9. (Problem 35)Circular primes

    The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...

随机推荐

  1. 0527 python 基础01

    折行的处理 \>>> print "hi \... hello Lucy!"hi hello Lucy! 自然字符串,字符串加上r或R前缀指定>>&g ...

  2. Bootstrap Alert 使用

    参考 http://www.bootcss.com/javascript.html#alerts 不过这里没有动态alert的例子 于是再参考http://stackoverflow.com/ques ...

  3. LintCode-两数之和

    题目描述: 给一个整数数组,找到两个数使得他们的和等于一个给定的数target. 你需要实现的函数twoSum需要返回这两个数的下标, 并且第一个下标小于第二个下标.注意这里下标的范围是1到n,不是以 ...

  4. 网上下载的“上下3D”和“左右3D”影片该如何播放?

    我们平常买的红蓝3D眼镜智能播放红蓝3D片源.网上找3D电影的时候,虽试图去找红蓝3D格式电影,但总会找到不少“左右格式”或者"上下格式"影片.正常播放后发现有两重画面.这种3D电 ...

  5. javascript 变量 命名规范 变量的作用域

    原文:javascript 变量 命名规范 变量的作用域 大家好,我是小强老师,今天讲解的是变量 变量 小时候我们学过  这个 应用题 :  X+1=2; 问  X 等于几?  答案是 1 对了,很聪 ...

  6. android基础篇------------java基础(12)(多线程操作)

    <一>基本概念理解 1.什么是进程? 进程就是在某种程度上相互隔离,独立运行的程序.一般来说,系统都是支持多进程操作的,这所谓的多进程就是让系统好像同时运行多个程序. 2.什么是线程呢? ...

  7. 令人作呕的OpenSSL

    在OpenSSL心脏出血之后,我相信非常多人都出了血,而且流了泪...网上瞬间出现了大量吐嘈OpenSSL的文章或段子,仿佛内心的窝火一瞬间被释放了出来,跟着这场疯闹,我也吐一下嘈,以雪这些年被Ope ...

  8. Ext JS学习第十七天 事件机制event(二)

    此文仅有继续学习笔记: 昨天说了三种邦定事件的方法,今天说一下自定义事件 假设现在又这样的情景一个自定义的事件 没有用到事件处理的场景        母亲问孩子和不饿->             ...

  9. HTML5 Web Storage使用实例

    很久没写文章了,忙加懒实在没办法,之前也看过关于Web Storage的文章,当时就觉得各各浏览器的支持跟上来还早着呢,像我们这样做门户网站的一时半会儿也用不上,毕竟用户群体鱼目混杂嘛,最近各各浏览器 ...

  10. java concurrency: ThreadLocal及其实现机制

    转载:http://shmilyaw-hotmail-com.iteye.com/blog/1703382 ThreadLocal概念 从字面上来理解ThreadLocal,感觉就是相当于线程本地的. ...