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

水题。。注意范围。!!!java用long型可以AC,只是注意中间计算结果也有可能溢出int型范围,也要转换为long才行。

还有,注意判断条件退出不是输入-1,而是输入小于0的数就是退出了。

import java.util.Scanner;

public class Main{
static long db[] = new long[100001];
public static void main(String[] args) {
dabiao();
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n =sc.nextInt();
if(n<0){
return;
}
System.out.println(db[n]);
}
}
private static void dabiao() {
db[1]=1;
db[2]=3;
for(int i=3;i<db.length;i++){
if(i%3==0){
db[i]=db[i-1]+i*(long)i*i;
//这里的i*i要强转成long,long*int还是long,否则i*i*i会超int范围
}else{
db[i]=db[i-1]+i;
}
} } }

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

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

  3. HDOJ(HDU).1016 Prime Ring Problem (DFS)

    HDOJ(HDU).1016 Prime Ring Problem (DFS) [从零开始DFS(3)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架 ...

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

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

  5. HDU 5475 An easy problem 线段树

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

  6. 数据结构(主席树):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 ...

  7. hdu 2055 An easy problem (java)

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

  8. HDU 2123 An easy problem

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

  9. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

随机推荐

  1. 利用MutationObserver对页面元素的改变进行监听

    'use strict'; let MutationObserver = window.MutationObserver || window.WebKitMutationObserver || win ...

  2. 什么是JPA

    起源 JPA由EJB 3.0软件专家组开发,作为JSR-220实现的一部分.但它不囿于EJB 3.0,你可以在Web应用.甚至桌面应用中使用.JPA的宗旨是为POJO提供持久化标准规范,由此可见,经过 ...

  3. root密码忘记了要怎么搞

    我是根据这几个教程做的,网址如下 http://www.pc6.com/infoview/Article_65979.html http://down.chinaz.com/server/201111 ...

  4. String的hashCode原理

    参考下面这篇文章: http://blog.csdn.net/steveguoshao/article/details/12576849 http://blog.csdn.net/mingli1986 ...

  5. (转)HTML表格边框的设置小技巧

    对于很多初学HTML的人来说,表格<table>是最常用的标签了,但对于表格边框的控制,很多初学者却不甚其解. 对于很多初学HTML的人来说,表格<table>是最常用的标签了 ...

  6. c#正则表达式采集数据

    protected void Page_Load(object sender, EventArgs e){ StringBuilder MyStringBuilder = new StringBuil ...

  7. 查询两个日期(时间)以内的数据,between and 或 and 连>= <=,to_date()

    between and 方法 select * from kk.kkhmd where larq between(to_date('2008-9-3','yyyy-mm-dd')) and (to_d ...

  8. Xcode添加静态库以及编译选项配置常见问题

    一,Xcode编译出现Link错误,出现"duplicate symbols for architecture i386 clang"提示.问题:链接时,项目有重名文件.解决:根据 ...

  9. OC - 25.CAKeyframeAnimation

    概述 简介 CAKeyframeAnimation又称关键帧动画 CAKeyframeAnimation是抽象类CAPropertyAnimation的子类,可以直接使用 通过values与path两 ...

  10. .net程序员必须知道的知识

    A while back, I posted a list of ASP.NET Interview Questions. Conventional wisdom was split, with ab ...