- 位数等于输入得数大小。
- 如果是奇数得话,平方一定在中间,然后算出最左边就可以(start = mid- num/2 2;)。如果偶数的话(start = mid- (2 num/2 -1);)
#include<bits/stdc++.h> using namespace std; int main(){ int num; while(cin>>num){ int flag = 0; if(num&1){ flag = 1; } int mid = pow(num,2); int z =0; int start = 0; if(flag){ start = mid- num/2 *2; }else{ start = mid- (2* num/2 -1); } for(int i=0; i< num;i++){ if(i==num-1){ cout<<start + i*2<<endl; }else{ cout<<start + i*2<<"+"; } } } return 0; }