Skip to content

⚡ Optimize factor finding loop in Euler Problem 3 to O(sqrt(N))#37

Open
ManupaKDU wants to merge 1 commit into
mainfrom
perf-euler-prob3-sqrt-bound-17468939605703781370
Open

⚡ Optimize factor finding loop in Euler Problem 3 to O(sqrt(N))#37
ManupaKDU wants to merge 1 commit into
mainfrom
perf-euler-prob3-sqrt-bound-17468939605703781370

Conversation

@ManupaKDU

Copy link
Copy Markdown
Contributor

💡 What: Changed the outer loop condition in Part-1/euler's project/Projects done/Problem 3.py to check for factors up to int(N**0.5) instead of N.
🎯 Why: To drastically reduce the number of iterations and execution time needed to find factors. A common mathematical optimization for finding divisors.
📊 Measured Improvement: Originally, the script hit a 5-second timeout during benchmarking. After the change, it correctly prints the prime numbers and finishes in ~0.6 seconds.


PR created automatically by Jules for task 17468939605703781370 started by @ManupaKDU

Change the upper bound of the `while` loop finding factors of `600851475143`
from `N` to `int(N**0.5)`. This reduces the number of loop iterations from
600+ billion to ~775,000, significantly improving execution time from timing
out (>5 seconds) to under 1 second.

Co-authored-by: ManupaKDU <95234271+ManupaKDU@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant