Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
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.

trying to cheat uh (spider week of code NITT)
 
Share this answer
 
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).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900