题目描述:
We once did a lot of recursional problem . I think some of them is easy for you and some if hard for you.
Now there is a very easy problem . I think you can AC it.
We can define sum(n) as follow:
if i can be divided exactly by 3 sum(i) = sum(i-1) + i*i*i;else sum(i) = sum(i-1) + i;
Is it very easy ? Please begin to program to AC it..-_-
水题,直接找出通项公式,需要注意的是,输入任意负数退出!!!坑爹,我以为输入-1退出,AC代码:
#include<stdio.h>
int main(){
__int64 n;
while(scanf("%I64d",&n)!=EOF && n>=0){
__int64 s=0,t=n/3;
s=n*(n+1)/2-3*t*(t+1)/2+t*t*(t+1)*(t+1)/4*27;
printf("%I64d\n",s);
}
}