解题思路:
等差数列前n项和:(首项+末项)x (项数) /2
首项: 1
末项: N 或 N-1 (N为奇数时末项就为N,为偶数时末项就为N-1)
项数:(N+1)/2 (利用整除效果,结果时趋零截断 比如 6(1 2 3)和5(1 2 3)的项数都为3)
注意事项:
参考代码:
#include <cstdio> #include <cstring> #include <string> #include <cmath> #include <functional> #include <iostream> #include <algorithm> using namespace std; int main() { int N; scanf("%d", &N); if(N%2==0) N--; printf("%d\n",(N+1)*(N+1)/4); return 0; }
0.0分
0 人评分
点我有惊喜!你懂得!浏览:1264 |
2004年秋浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:693 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:1130 |
钟神赛车 (C语言代码)浏览:897 |
时间转换 (Java代码)浏览:609 |
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:641 |
【数组的距离】 (C语言代码)浏览:776 |
输出正反三角形 (C语言代码)格式错误!!!浏览:1175 |
C语言训练-计算t=1+1/2+1/3+...+1/n (C语言代码)浏览:929 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:585 |