SarthakKeshari / CPP-Questions-and-Solutions

This repository aims to solve and create new problems from different spheres of coding. A path to help students to get access to solutions and discuss their doubts.
MIT License
47 stars 132 forks source link

polynomial root #377

Closed shreygupta2101 closed 2 years ago

shreygupta2101 commented 2 years ago

Issue Id you have worked upon -

359

Briefly explain your program logic -

So, let’s compute S = (6a-4b+4) for all ordered pairs (a, b) of values where a≥b. Now, for each pair (a, b) where 4a-4b+1 is a perfect square, subtract 6a-4b+4 and add (2a+1 + sqrt(4a - 4b +1))/2 +1 to S. now, After sorting array C, we can compute the first part in O(N) time. For each a, let’s iterate over odd d such that 4a-dd+1 ≥0. Each value b = (4a-d*d+1)/4 gives a perfect square and we can adjust their contribution accordingly.

Since the original array, C can contain duplicates, we can build the count array B where Bi denotes the number of occurrences of i. Pair (a, b) can be chosen in Ba * Bb ways.

Screenshots(Attach 2 screenshots of your own input and output) -

image

image


Checklist:

Eg - If your code follow the below guidelines. Kindly change [] to [x]

All the conditions should be fulfilled for considering your code for merging -

SarthakKeshari commented 2 years ago

@shreygupta2101, This PR will be marked as invalid and be closed by 13/10/2021(6PM). Kindly respond by either closing it or making the required changes.

shreygupta2101 commented 2 years ago

I'll do it by tomorrow 6 pm.

On Wed, 13 Oct 2021, 02:03 SarthakKeshari, @.***> wrote:

@shreygupta2101 https://github.com/shreygupta2101, This PR will be marked as invalid and be closed by 13/10/2021(6PM). Kindly respond by either closing it or making the required changes.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SarthakKeshari/CPP-Questions-and-Solutions/pull/377#issuecomment-941499754, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOJC2A5P4YZBCKRGJCV326TUGSLQZANCNFSM5FTZBAEA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

SarthakKeshari commented 2 years ago

I'll do it by tomorrow 6 pm. On Wed, 13 Oct 2021, 02:03 SarthakKeshari, @.***> wrote: @shreygupta2101 https://github.com/shreygupta2101, This PR will be marked as invalid and be closed by 13/10/2021(6PM). Kindly respond by either closing it or making the required changes. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#377 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOJC2A5P4YZBCKRGJCV326TUGSLQZANCNFSM5FTZBAEA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

@shreygupta2101, Ok I will wait