(Problem 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 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
前十个自然数的平方和是:
前十个自然数的和的平方是:
所以平方和与和的平方的差是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的更多相关文章
- (Problem 57)Square root convergents
It is possible to show that the square root of two can be expressed as an infinite continued fractio ...
- (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 ...
- (Problem 13)Large sum
Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 371072875339 ...
- (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 ...
- (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 ...
- (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 ...
- (Problem 37)Truncatable primes
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remo ...
- (Problem 36)Double-base palindromes
The decimal number, 585 = 10010010012(binary), is palindromic in both bases. Find the sum of all num ...
- (Problem 35)Circular primes
The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, ...
随机推荐
- Asp.net Role manager tutorial
It is very useful in .net we can user framework provided role manager, and easily configure in Web.C ...
- linux所有信息查询网址
- jQuery.merge 源码阅读
jQuery.merge(first,second) 概述 合并两个数组 返回的结果会修改第一个数组的内容——第一个数组的元素后面跟着第二个数组的元素. 参数 first:第一个待处理数组,会改变其中 ...
- linux使用技巧(shell/vi/screen)
1,Shell bash > awk '{print {NF}}' file 此时想修改操作命令可参照下面快捷方式 ctrl a 光标移动到命令最前面 ctrl e 光标移动到命令最后面 ctr ...
- uva311 - Packets(贪心)
题目:311 - Packets 题目大意:给出1*1, 2*2,3 *3, 4*4, 5*5, 6*6的箱子的个数,如今有若干个6*6的箱子,问最少用多少个箱子能够将给定的箱子都装进去. 解题思路: ...
- 调用AnimateWindow API来实现弹出效果
下面是实例的cs代码 public partial class frm_Main : Form { //使用Windows Api AnimateWindow [DllImport("use ...
- javascript事件及事件传输
函数必须调用才能执行,可a()加下面的函数调用 JS事件 1.js事件通常和函数结合来使用,这样可以通过发生的事件来驱动函数的执行,从而引起html出现不同的效果. 2.属性(当这些事件的属性发生时, ...
- iOS开发之第三方登录微信-- 史上最全最新第三方登录微信方式实现
项目地址 : https://github.com/zhonggaorong/weixinLoginDemo 最新版本的微信登录实现步骤实现: 1.在进行微信OAuth2.0授权登录接入之前,在 ...
- Javah生成JNI头文件
首先确保java的环境变量配置好了. 1:打开cmd 进入doc命令窗口: 进入class所在目录,我的class是在F:\summerVacation\ndkhelloworld\bin\class ...
- C语言之猜数字游戏
猜数字游戏 猜数字游戏是以前功能机上的一款益智游戏,计算机会根据输入的位数随机分配一个符合要求的数据,计算机输出guess后便可以输入数字,注意数字间需要用空格或回车符加以区分,计算机会根据输入信息给 ...