Problem 53094. Easy Sequences 51: Positive Gaussian Primes
A Gaussian Prime is a gaussian integer that cannot be decomposed as product of two non-unit gaussian integers (the complex units being: 1, , i and ). We say that a gaussian prime , is positive, if and .
Write a function that counts the number of elements of set, ,of all positive gaussian primes , such that p and q are both .
For example, for , the complete set of positive gaussian primes are as follows:
Therefore, for the function should return .
Solution Stats
Problem Comments
-
3 Comments
Michael Sisco
on 25 Dec 2021
I have a solution that works and the entire test suite can run in 18 seconds on my laptop, but takes a little over 45 seconds to run on the server, so the server times out on the test cases.
I'm stumped trying to figure out how I can optimize this code any further.
Michael Sisco
on 25 Dec 2021
I just re-ran the solution and this time it worked. I must have gotten a slow core the first time I ran it. ;-)
GeeTwo
on 19 Aug 2023
Michael Sisco and I have the same solutions, except that I skipped one check for primes (saved little or no time, as it turns out), and made it purely functional (no internal variables needed).
Solution Comments
Show commentsProblem Recent Solvers4
Suggested Problems
-
1409 Solvers
-
326 Solvers
-
95 Solvers
-
350 Solvers
-
154 Solvers
More from this Author116
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!