杭电2132

来源:互联网 发布:图书在版编目数据查询 编辑:程序博客网 时间:2024/06/04 23:19

题目描述:

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);}}


0 0
原创粉丝点击