HDOJ2132 An easy problem
来源:互联网 发布:汽车金融软件 编辑:程序博客网 时间:2024/06/10 23:16
An easy problem
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 14373 Accepted Submission(s): 3966
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..-_-
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.
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
123-1
Sample Output
1330
import java.util.Scanner;public class Main { private static Scanner scanner; private static long arr[]; public static void main(String[] args) { scanner = new Scanner(System.in); dabiao(); while (scanner.hasNext()) { int n = scanner.nextInt(); if (n < 0) { break; } System.out.println(arr[n]); } } private static void dabiao() { arr = new long[100001]; arr[1] = 1; for (long i = 2; i < arr.length; i++) { int j = (int)i; if(j%3 == 0){ //i*i*i的过程中 当i等于99999的时候 用int去存的话 有溢出 //(这里是吧i*i*i的值放在一个int的空间里面 然后再进行赋值运算 要尤其注意) arr[j] = arr[j-1]+i*i*i; }else { arr[j] = arr[j-1]+j; } } }}
阅读全文
0 0
- HDOJ2132 An easy problem
- An Easy Problem
- 2055 An easy problem
- An Easy Problem!
- An Easy Problem!
- poj2826 An Easy Problem?!
- HDOJ2055 An easy problem
- An Easy Problem
- hdu-An Easy Problem
- hdu2601 An easy problem
- An Easy Problem
- hdu-An Easy Problem
- HDU_2055 An easy problem
- HDU_2123 An easy problem
- B - An easy problem
- B - An easy problem
- An easy problem
- An easy problem 2132
- java运算符的优先级
- JS生成随机数
- 如何让应用支持 Android 8.0 自动填充?
- 【功能代码】---1.通过Jquery来处理复选框
- COMP2907 W1 稳定匹配
- HDOJ2132 An easy problem
- DIY激光竖琴
- WEB-INF目录与META-INF目录的作用
- 1075. 链表元素分类(25)
- AndroidStudio:x.Ext.init(this);初始化时this报红(错)(171130
- 二、开始Tango API(Unity版)
- zynq 7000 自定义IP 实验
- 浏览器 history location pushstate的解决疑问
- 10分钟让你明白MySQL是如何利用索引的