TopCoder problem "SumOfPowers" used in SRM 397 (Division I Level Two)



Problem Statement

    

NOTE: This problem statement contains superscripts that may not display properly if viewed outside of the applet.



You are given ints n and k. Return the value of the sum 1k + 2k + 3k + ... + nk modulo 1000000007.

 

Definition

    
Class:SumOfPowers
Method:value
Parameters:int, int
Returns:int
Method signature:int value(int n, int k)
(be sure your method is public)
    
 

Constraints

-n will be between 1 and 109, inclusive.
-k will be between 1 and 50, inclusive.
 

Examples

0)
    
5
1
Returns: 15
Here, we have arithmethic progression: 1 + 2 + 3 + 4 + 5 = 15.
1)
    
4
2
Returns: 30
Just a little bit more complicated example here: 12 + 22 + 32 + 42 = 1 + 4 + 9 + 16 = 30.
2)
    
13
5
Returns: 1002001
This one would be harder to check by hand.
3)
    
123456789
1
Returns: 383478132

Problem url:

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

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=12169&pm=8725

Writer:

mateuszek

Testers:

PabloGilberto , Olexiy , ivan_metelsky , ged

Problem categories:

Advanced Math