标签:hdu2132
1 2 3 -1
1 3 30
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]); } } }
#include <stdio.h> #define maxn 100005 typedef __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】
标签:hdu2132
原文地址:http://blog.csdn.net/chang_mu/article/details/40867165