The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 3025
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=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; }
Answer:
|
25164150 |
相关推荐
Problem 6 前十个自然数的平方和是 1² + 2² + ... + 10² = 385 前十个自然数之和的平方是, (1 + 2 + ... + 10)² = 55² = 3025 因此,前十个自然数的平方和与平方和之差为3025-385 = 2640。 求出前一百个自然数...
# [LeetCode](https://leetcode.com/problemset/algorithms/)  [![License]...
python教程学习
tdac034.pdf
veclibm111111111111
nssm工具,进行2次解压后即可
视讯镜头优化,操作不走
【数据结构】的资源,包括书籍、在线课程和网站
北京大学-DeepSeek系列-提示词工程和落地场景.pdf.png
【财信国际经济研究院-2025研报】2025年2月CPI和PPI数据点评:通胀低于预期,内需亟待提振.pdf
【毕业设计】java-springboot+vue精品在线试题库系统源码(完整前后端+mysql+说明文档+LunW).zip
python安装-25.求 a 的 b 次方——有点不好意思哈.py
代码实现了自适应IMM(交互式多模型)算法,专注于对目标状态进行估计,并结合了匀速(CV)和匀加速(CA)运动模型。它使用自适应观测噪声估计和扩展卡尔曼滤波器(EKF)作为滤波主体,并在最后提供误差统计特性输出。
中产品工业物联网联网的基础功能,是企业开启数字化转型的入门之选。它能帮助企业快速搭建起基础的设备数据采集与监控体系,以较低成本实
北京大学DeepSeek系列-DeepSeek与AIGC应用.pdf.png
【毕业设计-java】springboot-vue基于多维分类的知识管理系统实现源码(完整前后端+mysql+说明文档+LunW).zip
## 一、数据介绍 本数据参考C刊《管理评论》佟岩(2024)老师的做法,使用各年度省级政府工作报告中“减碳”关键词的词频总数来测度地方政府对“减碳”的重视程度,“减碳”关键词包括二氧化碳、低碳、减排、节能、能耗、环境保护(环保)、生态、绿色。 本数据包含:原始数据、参考文献、代码do文件、最终结果。 ## 二、参考文献: 佟岩,李鑫,徐国铨.企业集团碳减排压力与债务分布-来自高耗能上市公司的经验证据[J].管理评论,2024,36(02):210-221.DOI:10.14120/j.cnki.cn11-5057/f.2024.02.014 ## 三、相关数据:城市、城市编码、年份、减碳重视程度词频。
python教程学习
jfinal-undertow 用于开发、部署由 jfinal 开发的 web 项目
python学习一些项目和资源