The range for a,b,c would be 0 to sqrt(n). Iterating over all values would give complexity O(n^(3/2)).
Using bitmaps, we can determine which numbers within 0..n are not in the list of a^2 + b^2 + c^2.
I guess, here we need to assume that we have O(n) space atleast.
For making computationally efficient, use ranges for a, b, c as [0..sqrt(n)], [a .. sqrt(n)], [b..sqrt(n)].
~Vishal
On 10/31/06, Dhyanesh (ધયાનેશ) <[EMAIL PROTECTED]> wrote:
I have a slight improvement O ( n^2 log (n ) )
Say you have a^2 + b^2 + c^2 = d.
Keep a sorted list of all possible a^2 + b ^ 2 ... this would take n^2 time to generate and n^2 log n to sort. Now loop over all possible 'd' and 'c' and compute d - c ^ 2. Use binary search to determine whether that number is in the list ... if it is then 'd' is a number which CAN be represented otherwise try for the next 'c'.
There might be a better solution ... still thinking
-Dhyanesh
On 10/31/06, Karthik Rathinavelu < [EMAIL PROTECTED]> wrote:Question: Given n, find the numbers in the range of 0...n which CAN'T be represented in the form of sum of squares of 3 non-negative numbers.
If anyone could possibly give a solution better than O(n^3), it will be good.
Thanks,
R.Karthik
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups-beta.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---
- [algogeeks] Proving Waring hypothesis... Karthik Rathinavelu
- [algogeeks] Re: Proving Waring hypothes... Jair Cazarin
- [algogeeks] Re: Proving Waring hypothes... Dhyanesh (ધયાનેશ)
- [algogeeks] Re: Proving Waring hypo... Vishal
Reply via email to