(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, ...
随机推荐
- linux文件系统操作——底层文件访问
在不使用标准I/O的情况下,使用write,read,open实现对文件的复制操作,这些调用都是直接使用底层系统调用,完成从用户代码到内核代码的切换,消耗大量的系统资源,今天对此进行研究主要是 ...
- 高质量程序设计指南C/C++语言——有了malloc/free为什么还要new/delete?
- javascript学习笔记(window .alert 是什么)
<script language="javascript"> var abc="25"; window .alert(abc); </scri ...
- protel99se中做拼板图解
很多时候我们要在protel99se中做拼板, 但是通常在复制进行拼版的时候会出现如下的效果,元件被重新命名了. 而无法达到我们需要的像下图的效果 那我们怎么办,才能达到上图的效果呢?其实操作很简单. ...
- Spring Cache使用详解
Spring Cache Spring Cache使用方法与Spring对事务管理的配置相似.Spring Cache的核心就是对某个方法进行缓存,其实质就是缓存该方法的返回结果,并把方法参数和结果用 ...
- Installing on CentOS/RHEL / KB forum / Ajenti
Installing on CentOS/RHEL / KB forum / Ajenti Ajenti → KB → Installation Is it?: Inappropriate Spam ...
- Android 中文API (69) —— BluetoothAdapter[蓝牙]
前言 本章内容是 android.bluetooth.BluetoothAdapter,为Android蓝牙部分的章节翻译.本地蓝牙设备的适配类,所有的蓝牙操作都要通过该类完成.版本为 Androi ...
- Ext JS学习第二天 我们所熟悉的javascript(一)
此文用来记录学习笔记: •ExtJS是一个强大的javascript框架,如果想真正的掌握ExtJS,那么我们必须要对javascript有一定的认识,所以很有必要静下心来,抱着一本javascrip ...
- Hadoop2.6 Ha 安装
Hadoop 2.6安装文档 版本说明:hadoop 2.6 linux-64位 Zookeeper3.4.6 jdk 1.7.0_75 1. Ssh无密码 ssh-keygen vim ...
- zoj p3780 Paint the Grid Again
地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5267 题意:Leo 有一个N*N 的格子,他又有一把魔法刷,这个刷子能把 ...