will this work. n size of array. cal (a[i] - min(arr) + 1). now cal sum of a[i], cal square sum of array as (a[i] * a[i]) , cal cube sum of array as (a[i] * a[i] * a[i]). now if array elements are consecutive then sum must be n * (n + 1) / 2. square sum must be (n * (n + 1) * (2n + 1) )/ 6 and cube sum must be (n * (n + 1) / 2) ^ 2.
On Fri, Jun 24, 2011 at 11:00 PM, Adarsh <[email protected]> wrote: > I think I got an work around for this.... if number of elements are > not odd why not make them odd :) > I variation to my prev algo > > int n = A.size(); > for (int i=0; i<n; i++) > total += A[i]; > findMinMax(A[1...n]); //returns first smallest (fmin), second smallest > (smin) and largest (max) element in array > > int fmean = (max+fmin)/2; > int smean = (max+smin)/2; > stotal = total - fmin; > if ((total - n*fmean) == 0) > { > if ((stotal - n*smean) == 0) > printf("consecutive\n"); > return; > } > printf("not consecutive\n"); > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- Varun Pahwa B.Tech (IT) 7th Sem. Indian Institute of Information Technology Allahabad. Ph : 09793899112 ,08011820777 Official Email :: [email protected] Another Email :: [email protected] People who fail to plan are those who plan to fail. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
