I used the following code to found if a specific number is a perfect square:
Clear["Global`*"];
ParallelTable[
If[IntegerQ[Sqrt[ ...]], ..., Nothing], {..., ..., ...}] //. {} ->
Nothing
Mathematice can do this for numbers up to:
$MaxMachineNumber
1.79769*10^308
But my code is way, way too slow. Is there an other way to write the code in Mathematica that will be much faster?
I would accept a recommendation to use another programming language to find if a number is a perfect square for large values (like $10^{12}$ and bigger)? I know that ULLONG_MAX in C++ can handle values up to $18446744073709551615$. But code in C++ is slow for larger values. I also thought about using properties of square numbers in my program, but that means that I also need to compute the values.
NumberTheory`PowersRepresentationsDump`ProbablePerfectSquareQ. – MarcoB Jan 03 '21 at 15:17isqrtthat computes integer square roots and that will return-1if a number is not a perfect square. It's quite fast and may work for you too. Depending on your use case you can setmyintto be 64-bits instead of 128-bits (usingtypedef int64_t myint;at the beginning of the code), which will make the code still much faster. – Roman Jan 03 '21 at 18:14