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. 开了几天的phpmyadmin的总结

    近来无事,免费体验了一波腾讯云的vps,打了一个phpstudy,全部默认的配置,只不过,没有给他写入文件的权限 开启了日志,看了下,这几天黑客们的活动 首先,有两三个ip来爆破我的phpmyadmi ...

  2. C语言链栈

    链栈与链表结构相似 typedef int elemtype; typedef struct linkedStackNode{ elemtype e; struct linkedStackNode * ...

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

    20155202张旭 2016-2017-2 <Java程序设计>第2周学习总结 教材学习内容总结 第一,二章知识小节: git log 命令来查看 :提交历史 查看当前所处位置: pwd ...

  4. 20155209实验一《Java开发环境的熟悉》实验报告

    20155209实验一<Java开发环境的熟悉>实验报告 实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Java程序. 实验步骤一 ...

  5. css3新增的content 的用法:

    <-----------------------------------------------文字加在内容后面----------------------------------------- ...

  6. Hibernate 3.0 HelloWorld

    说明 基于Hibernate 3.0,Mysql5.0,java jdk 1.7,运行需要的lib 库,从http://files.cnblogs.com/HCCZX/Hibernate_Lib.ra ...

  7. day2 self __init__ __str__

    1 self  谁调用指向谁自己  相当于其他语言的this #1.类名 class Cat(): #大驼峰的命名规范 #2.类的属性 #3.类的方法 def eat(self): print(&qu ...

  8. 【LG3206】[HNOI2010]城市建设

    [LG3206][HNOI2010]城市建设 题面 洛谷 题解 有一种又好想.码得又舒服的做法叫线段树分治+\(LCT\) 但是因为常数过大,无法跑过此题. 所以这里主要介绍另外一种玄学\(cdq\) ...

  9. 4825: [Hnoi2017]单旋

    4825: [Hnoi2017]单旋 链接 分析: 以后采取更保险的方式写代码!!!81行本来以为不特判也可以,然后就总是比答案大1,甚至出现负数,调啊调啊调啊调~~~ 只会旋转最大值和最小值,以最小 ...

  10. 解析hdr图像文件的python实现

    如题 import cv2 import numpy as np def rgbe2float(rgbe): res = np.zeros((rgbe.shape[0],rgbe.shape[1],3 ...