http://acm.hdu.edu.cn/showproblem.php?pid=2132

Problem Description
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..-_-
 
Input
  The input file contains multilple cases.
  Every cases contain only ont line, every line contains a integer n (n<=100000).
  when n is a negative indicate the end of file.
 
Output
  output the result sum(n).
 
Sample Input
1
2
3
-1
 
Sample Output
1
3
30

代码:

#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
long long sum[maxn]; int main() {
sum[0] = 0;
for(long long i = 1; i < maxn; i ++) {
if(i % 3 == 0)
sum[i] = sum[i - 1] + i * i * i;
else
sum[i] = sum[i - 1] + i;
}
int x;
while(~scanf("%d", &x)) {
if(x < 0)
break;
else
printf("%lld\n", sum[x]);
}
return 0;
}

  

HDU 2132 An easy problem的更多相关文章

  1. HDOJ(HDU) 2132 An easy problem

    Problem Description We once did a lot of recursional problem . I think some of them is easy for you ...

  2. hdu 5475 An easy problem(暴力 || 线段树区间单点更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

  3. HDU 5475 An easy problem 线段树

    An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  4. 数据结构(主席树):HDU 4729 An Easy Problem for Elfness

    An Easy Problem for Elfness Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65535/65535 K (J ...

  5. hdu 2055 An easy problem (java)

    问题: 開始尝试用字符做数组元素.可是并没实用. 在推断语句时把a z排出了. An easy problem Time Limit: 1000/1000 MS (Java/Others)    Me ...

  6. HDU 2123 An easy problem

    http://acm.hdu.edu.cn/showproblem.php?pid=2123 Problem Description In this problem you need to make ...

  7. HDOJ(HDU) 2123 An easy problem(简单题...)

    Problem Description In this problem you need to make a multiply table of N * N ,just like the sample ...

  8. HDU 4729 An Easy Problem for Elfness (主席树,树上第K大)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 题意:给出一个带边权的图.对于每一个询问(S , ...

  9. HDU - 3521 An easy Problem(矩阵快速幂)

    http://acm.hdu.edu.cn/showproblem.php?pid=3521 题意 对于矩阵A,求e^A的值. 分析 这个定眼一看好像很熟悉,就是泰勒展开,可惜自己的高数已经还给老师了 ...

随机推荐

  1. 20155323 2016-2017-2 《Java程序设计》第2周学习总结

    20155323 2016-2017-2 <Java程序设计>第2周学习总结 教材学习内容总结 对象:对象是类的一个实例,有状态和行为. 类:类是一个模板,它描述一类对象的行为和状态. 第 ...

  2. ## 20155336 2016-2017-2《JAVA程序设计》第十周学习总结

    20155336 2016-2017-2<JAVA程序设计>第十周学习总结 学习任务 完成学习资源中相关内容的学习 参考上面的学习总结模板,把学习过程通过博客(随笔)发表,博客标题“学号 ...

  3. 20155338 2016-2017-2 《Java程序设计》第3周学习总结

    20155338 2016-2017-2 <Java程序设计>第3周学习总结 教材学习内容总结 本周学习量比较多,但是知识点并不是特别难,学习了书本的第四五章,其中个人重点学习了数组对象. ...

  4. addClass+siblings+removeClass用意:

    $(this).addClass("li_add").siblings().removeClass("li_add").children('.floor2'). ...

  5. 【SQLSERVER】递归查询算法实例

    一.递归查询 1.结构: 递归CTE最少包含两个查询(也被称为成员). 第一个查询为定点成员,定点成员只是一个返回有效表的查询,用于递归的基础或定位点. 第二个查询被称为递归成员,使该查询称为递归成员 ...

  6. centos安装smokeping

    本文摘自网友博客,并亲自验证 博客地址:https://blog.csdn.net/erica_yue/article/details/78455101 1.安装依赖包: yum install -y ...

  7. 【BZOJ2004】[HNOI2010]Bus 公交线路

    [BZOJ2004][HNOI2010]Bus 公交线路 题面 bzoj 洛谷 题解 $N$特别大$P,K$特别小,一看就是矩阵快速幂+状压 设$f[S]$表示公交车状态为$S$的方案数 这是什么意思 ...

  8. LUA中点号和冒号的区别

    Student = {}; Student.__index = Student; function Student:new(name, age) local temp = {}; setmetatab ...

  9. 解决WCF传输的数据量过大问题

    今天写了个WCF接口,然后自测通过,和别人联调时报 远程服务器返回错误: (413) Request Entity Too Large        错误!记得以前写的时候也出现过这个错误,大致解决办 ...

  10. javaweb(十)——HttpServletRequest对象(一)

    一.HttpServletRequest介绍 HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中,通过这个对象 ...