An easy problemTime
limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total Submission (s): 9194 Accepted Submission (s): 2491
Problem Descriptionwe once did a lot of recursional problem. I think some of them is easy for you and some if hard for you.
Now there are 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 with 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
123-1
Sample Output
1330
Authorwendell
SOURCEHDU 2007-11 programming Contest_warmup Java water too.
Import Java.util.scanner;import Java.math.biginteger;public class Main { static final int maxn = 100005; Static biginteger[] arr = new BIGINTEGER[MAXN]; public static void Main (string[] args) { Scanner cin = new Scanner (system.in); Arr[0] = Biginteger.zero; BigInteger tmp; for (int i = 1; I <= 100000; ++i) { tmp = biginteger.valueof (i); if (i% 3 = = 0) Arr[i] = Arr[i-1].add (tmp.multiply (TMP). Multiply (TMP)); else Arr[i] = Arr[i-1].add (TMP); } int n; while (true) { n = cin.nextint (); if (n < 0) break; System.out.println (Arr[n]);}}
C code seems to be simpler.
#include <stdio.h> #define MAXN 100005typedef __int64 LL; LL Arr[maxn];int Main () { int n, i; for (i = 1; I <= 100000; ++i) if (i% 3) arr[i] = arr[i-1] + i; else arr[i] = Arr[i-1] + (LL) i * i * i; while (scanf ("%d", &n), n >= 0) printf ("%i64d\n", Arr[n]);}
HDU2132 an easy Problem "Java"