Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = 6962155154859963260211100482357357666900094513013513488352858667799199787495340476167566639530574848375895722792291996203873323650274512138128403360943634134259376986501375967452208380337012919869885380406071772232795575963202558402893589313281327208179913789760736615950818685956393838601277519011418885197723428318400763080858914698836058070301404903262955501113318317950597435778777212408626799143;
- PrimeQ[n];
- qQ::usage =
- "SqQ[n] is True when n is an exact square, and False otherwise.";
- (*We reduce n modulo a product of small primes and use*)
- (*pre-computed tables of Jacobi symbols to filters out*)
- (*most non-squares with a single multi-precision operation.*)
- (*We use IntegerQ[Sqrt[n]] on less than 1/11595 integers.*)
- (*Pre-computed variables starting in SqQ$ are for internal use;*)
- SqQ$m = (SqQ$0 = 59*13*7*5*3)*(SqQ$1 = 23*19*17*11)*(SqQ$2 =
- 47*37*31)*(SqQ$3 = 43*41*29);
- SqQ$u = SqQ$v = SqQ$w = SqQ$x = 0;
- Block[{j},
- For[j = SqQ$0, j-- > 0,
- SqQ$u +=
- SqQ$u + If[
- JacobiSymbol[j, 59] < 0 || JacobiSymbol[j, 13] < 0 ||
- JacobiSymbol[j, 7] < 0 || JacobiSymbol[j, 5] < 0 ||
- JacobiSymbol[j, 3] < 0, 1, 0]];
- For[j = SqQ$1, j-- > 0,
- SqQ$v +=
- SqQ$v + If[
- JacobiSymbol[j, 23] < 0 || JacobiSymbol[j, 19] < 0 ||
- JacobiSymbol[j, 17] < 0 || JacobiSymbol[j, 11] < 0, 1, 0]];
- For[j = SqQ$2, j-- > 0,
- SqQ$w +=
- SqQ$w + If[
- JacobiSymbol[j, 47] < 0 || JacobiSymbol[j, 37] < 0 ||
- JacobiSymbol[j, 31] < 0, 1, 0]];
- For[j = SqQ$3, j-- > 0,
- SqQ$x +=
- SqQ$x + If[
- JacobiSymbol[j, 43] < 0 || JacobiSymbol[j, 41] < 0 ||
- JacobiSymbol[j, 29] < 0, 1, 0]]];
- (*The function itself starts here*)
- SqQ[n_Integer] :=
- Block[{m = Mod[n, SqQ$m]},
- BitGet[SqQ$u, Mod[m, SqQ$0]] == 0 &&
- BitGet[SqQ$v, Mod[m, SqQ$1]] == 0 &&
- BitGet[SqQ$w, Mod[m, SqQ$2]] == 0 &&
- BitGet[SqQ$x, Mod[m, SqQ$3]] == 0 && IntegerQ[Sqrt[n]]]
- (*Automatically thread over lists*)
- SetAttributes[SqQ, Listable];
- u0 = u = Block[{$MaxExtraPrecision = 1000}, Ceiling[Sqrt[n]]];
- v = u^2 - n;
- While[! SqQ[v], v += u; v += u += 1];
- p = u - Sqrt[v];
- q = n/p;
- {u - u0, p, q}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement