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<iostream>
using namespace std;
int main()
{
    __int64 i,n,a[100001];
    a[0]=0;
    for(i=1;i!=100001;++i)
    {
        if(i%3==0)
            a[i]=a[i-1]+i*i*i;//////  i*i*i的过程中 当I等于99999的时候 用int去存的话 有溢出(这里是吧i*i*i的值放在一个int的空间里面 然后再进行赋值运算  要尤其注意)
        else
            a[i]=a[i-1]+i;
    }
    while(cin>>n&&n>=0)
    {
        cout<<a[n]<<endl;
    }
    return 0;
}

hdu 2132... 被基本问题考住了。。的更多相关文章

  1. HDU 2132 An easy problem

    http://acm.hdu.edu.cn/showproblem.php?pid=2132 Problem Description We once did a lot of recursional ...

  2. HDU 1042 N! 參考代码

    HDU 1042 N! 题意:给定整数N(0 ≤ N ≤ 10000), 求 N! (题目链接) #include <iostream> using namespace std; //每一 ...

  3. 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 ...

  4. 【hdu多校联考第二场】Odd Shops

    Description 这道题的题意是这道难读,大概就是给你n个商店,每个商店的重量为i的商品用ai表示,对于任意商店的a数列都是相同的,重量的范围为[1,10] 求购买方案总数为奇数的重量一共有多少 ...

  5. hdu 4612 Warm up(缩点+树上最长链)

    本来就是自己负责图论,结果水了= = 题目其实很裸,就是求桥的数量,只是要新加上一条边罢了.做法:先缩点.再在树上搜最长链(第一场多校的hdu 4607Park Visit就考了最长链,小样,套个马甲 ...

  6. SPFA

    SPFA算法用来求单源最短路.可以处理任何有解的情况. 先建一个数组\(dist_x = 起点到x的最短路长度\),当\(x=起点\)时为0,当x和起点不通时为INF(本题中为\(2^31-1\)). ...

  7. 最短路洛谷P2384

    题目背景 狗哥做烂了最短路,突然机智的考了Bosh一道,没想到把Bosh考住了...你能帮Bosh解决吗? 他会给你100000000000000000000000000000000000%10金币w ...

  8. 20155205 2016-2017-2《Java程序设计》课程总结

    20155205 2016-2017-2<Java程序设计>课程总结 目录 一.每周作业链接汇总 二.实验报告链接汇总 三.博客中的经验与收获 - 自认为写得最好一篇博客是?为什么? - ...

  9. P2384 最短路

    题目背景 狗哥做烂了最短路,突然机智的考了Bosh一道,没想到把Bosh考住了...你能帮Bosh解决吗? 他会给你100000000000000000000000000000000000%10金币w ...

随机推荐

  1. Python——graphviz及pydotplus安装步骤

    Python——graphviz及pydotplus安装步骤 一.安装Graphviz 网站:http://www.graphviz.org/download/ 下载msi文件 直接安装,完成之后添加 ...

  2. 解决request.getSession().getServletContext().getRealPath("/")为null问题

    今天把程序部署到服务器,发现异常,FileNotFound异常,很快定位到getServletContext().getRealPath("/");返回空的问题.这个问题通常是传递 ...

  3. Android 调用.Net WCF服务 .

    本来以为在java平台上用axis2生成了客户端代理类然后移植到Android平台上就好了.没想到在移植过程中出现了很多问题.说明JVM和android的DVM差距还是很大的. JVM执行的是clas ...

  4. AI项目(CV方向)研发流程

  5. Postgresql常用函数整理

    一.字符串函数 1.函数:string || string(string || non-string) 说明:字符串(或与非字符串)连接 示例: 2.函数:char_length(string) 说明 ...

  6. Android输入法遮挡了输入框,使用android:fitsSystemWindows="true"后界面顶部出现白条解决方案

    我的最外层是LinearLayout,自定义CustomLinearLayout继承LinearLayout,重写fitSystemWindows和onApplyWindowInsets两个方法: p ...

  7. pip 安装指定版本

    pip在安装包的时候可以不需要从网上下载,以windows的scipy为例 pip install scipy==0.15.1 以上表示安装0.15.1版本的scipy,这里用”==”接版本,如果权限 ...

  8. windows驱动程序中的预处理含义

    #pragma  code_seg(“PAGE”) 作用是将此部分代码放入分页内存中运行. #pragma  code_seg() 将代码段设置为默认的代码段 #pragma  code_seg(&q ...

  9. 【Java】分布式自增ID算法---雪花算法 (snowflake,Java版)

    一般情况,实现全局唯一ID,有三种方案,分别是通过中间件方式.UUID.雪花算法. 方案一,通过中间件方式,可以是把数据库或者redis缓存作为媒介,从中间件获取ID.这种呢,优点是可以体现全局的递增 ...

  10. yii2 HeadersAlreadySentException 报错 解决方案

    报错如下: An Error occurred while handling another error: exception  Stack trace: # /xxxx/xxxx/vendor/yi ...