题解 | #牛牛学数列#
牛牛学数列
https://www.nowcoder.com/practice/0b97367cd2184c12a0e02f7c223aee11
#include <stdio.h> int main() { int m,n,o,p; int sum1=0; int sum2=0; int sum3=0; scanf("%d",&n); for(m=1;m<=n;m++) { if(m%2==0) { o=m/2; sum2=sum2+2*o; } else{ p=(m+1)/2; sum1=sum1+2*p-1; }} sum3=sum1-sum2; printf("%d",sum3); return 0; }