15,903,203 members
See more:
Basically f(x) is summation of power K of absolute value of difference of every pair of array.In this question n(number of element in array),k,and element will be given and i have to fine first absolute difference between every pair of array and raise its power k, then add all them and find the answer%pow(10,9)+7

What I have tried:

I tried this problem by using 3 loops , one for power. because value of k can be go till 100000,and element of array can be go till 10^9
Posted
Updated 6-Apr-20 11:02am
k5054 5-Apr-20 14:31pm
Maybe you can post the exact problem you are trying to solve? As stated it would appear that you need to be able to calculate values in with a magnitude of the order of 1E+900000. That value is far too large for even a long double in 64 bits which would be of the order 1E+4932, so there must be some other constraints on the problem, OR you are expected to use a bignum library to compute the values.
That being said, you should also post your code. We are quite happy to review your solution and suggest fixes, but we don't provide solutions outright.

## Solution 1

trying to cheat uh (spider week of code NITT)

## Solution 2

Instead of using three loops with complexity O(n^3), you can use modular exponentiation as the third loop which will take O(log n) to compute power k for the difference of each pair of the array.
I want to add in this question how can we compute summation of differences of each pair raise to power k in less than O(n^2 log n).