3 2
4 2
3 6
3 7
代码如下:
#include <iostream> using namespace std; int main() { int n,m; while (cin>>n>>m) { if (n==0&&m==0) break; int i,count = 0,t = 0,sum = 0; for (i=1; i<=n; i++) { count++; t += 2; sum += t; if (i == n) { cout<<sum/count; } else if (count == m) { cout<<sum/m<<" "; count = 0; sum =0; } } cout<<endl; } return 0; }
运行结果:
原文地址:http://blog.csdn.net/liuchang54/article/details/45476515