UVa 11718 - Fantasy of a Summation

sum = a[1] + a[2] + a[3] + ... + a[n-1] ;

res = ( sum * n^(k-1) * k ) % mod