TopCoder problem "PowSum" used in TCO '03 Round 1 (Division I Level One)



Problem Statement

    Given an int low, an int high, and an int pow, return the sum of i^j, for all i between low and high, inclusive, and all j between 1 and pow, inclusive.
 

Definition

    
Class:PowSum
Method:getSum
Parameters:int, int, int
Returns:int
Method signature:int getSum(int low, int high, int pow)
(be sure your method is public)
    
 

Constraints

-low will be between -100 and 100, inclusive.
-high will be between low and 100, inclusive.
-pow will be between 1 and 10, inclusive.
-The return value will fit in a signed 32 bit datatype.
 

Examples

0)
    
1
3
2
Returns: 20
 1^1 + 2^1 + 3^1 + 1^2 + 2^2 + 3^2 = 
 1 + 2 + 3 + 1 + 4 + 9 =
 20
1)
    
-12
12
9
Returns: 1637738440
Note that intermediate values may exceed the 32 bit restriction.
2)
    
-100
100
2
Returns: 676700

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=1821

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4702&pm=1821

Writer:

lars2520

Testers:

Problem categories:

Simple Math