解题思路:
注意事项:
参考代码:
#include<iostream> using namespace std; int main() { int a[1024]; int n, m, t ,acount; while (cin >> n >> m) { a[1] = 2; for (int i = 2; i <= n; i++)//用递归先给数组每个元素赋值 { a[i] = a[i - 1] + 2; } t = n / m; for (int i = 1; i <= t; i++) { acount = 0; for (int j = (i - 1)*m + 1; j <= i * m; j++)//每m个断开,算一次,n不能被m整除的部分后面操作 { acount += a[j]; } cout << acount / m << " "; } if (n%m != 0)//将剩余的部分额外操作 { acount = 0; for (int i = t * m + 1; i <= n; i++) { acount += a[i]; } cout << acount / (n - t * m);//n-t*m+1-1 } cout << endl; } return 0; }
0.0分
22 人评分