Problem 49738. Determine whether a prime is Pythagorean
Pythagorean primes get their name from the property that they can be written as the sum of two squares. For example,
. Cody Problem 45964 asked you to find the nth Pythagorean prime and two numbers whose squares will produce the prime. This problem merely asks you to determine whether a prime can be written as the sum of two squares.
Write a function to determine whether a prime is Pythagorean. All input numbers in the tests are prime. Because some are large, they are given as strings.
Solution Stats
Problem Comments
-
3 Comments
Nicolas Douillet
on 16 Jun 2025
As far as I understand the assert function, the tests #13, 15, 17 and 18 actually appear to be wrong (!) since accordind to Matlab isprime function theirs inputs are not prime numbers (resp 99194853094755497, 1066340417491710595814572169, 19134702400093278081449423917, and 10888869450418352160768000001). Could you please double check these tests ? Thank you.
Christian Schröder
on 16 Jun 2025
@Nicolas they're all primes, but they all exceed flintmax, and I think isprime() does not handle such numbers reliably (arguably something its documentation should mention).
Nicolas Douillet
on 16 Jun 2025
Thank you Christian for explanation :-)
Solution Comments
Show commentsProblem Recent Solvers29
Suggested Problems
-
655 Solvers
-
Arrange Vector in descending order
12699 Solvers
-
1523 Solvers
-
544 Solvers
-
148 Solvers
More from this Author314
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!