
前n个奇数的平方系列取系列中前n个奇数的平方。
系列是:1,9,25,49,81,121…
该级数也可以写为 - 12, 32, 52, 72, 9 2, 112….
这个级数的和有一个数学公式 -
n(2n+1) (2n-1)/ 3= n(4n2 - 1)/3
启科网络商城系统由启科网络技术开发团队完全自主开发,使用国内最流行高效的PHP程序语言,并用小巧的MySql作为数据库服务器,并且使用Smarty引擎来分离网站程序与前端设计代码,让建立的网站可以自由制作个性化的页面。 系统使用标签作为数据调用格式,网站前台开发人员只要简单学习系统标签功能和使用方法,将标签设置在制作的HTML模板中进行对网站数据、内容、信息等的调用,即可建设出美观、个性的网站。
0
举个例子,
Input: N = 4 Output: sum =
12 + 32 + 52 + 72 = 1 +9+ 25 + 49 = 84
使用公式,和 = 4(4(4)2- 1)/3 = 4(64-1)/3 = 4(63)/3 = 4*21 = 84 这两种方法都是好的,但使用数学公式的方法更好,因为它不使用外观,从而减少了时间复杂度。
#include <stdio.h>
int main() {
int n = 8;
int sum = 0;
for (int i = 1; i <= n; i++)
sum += (2*i - 1) * (2*i - 1);
printf("The sum of square of first %d odd numbers is %d",n, sum);
return 0;
}The sum of square of first 8 odd numbers is 680
#include <stdio.h>
int main() {
int n = 18;
int sum = ((n*((4*n*n)-1))/3);
printf("The sum of square of first %d odd numbers is %d",n, sum);
return 0;
}The sum of square of first 18 odd numbers is 7770
以上就是前n个奇数的平方和的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号