Advertisement
Guest User

Untitled

a guest
Jul 11th, 2021
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. n = 6962155154859963260211100482357357666900094513013513488352858667799199787495340476167566639530574848375895722792291996203873323650274512138128403360943634134259376986501375967452208380337012919869885380406071772232795575963202558402893589313281327208179913789760736615950818685956393838601277519011418885197723428318400763080858914698836058070301404903262955501113318317950597435778777212408626799143;
  2.  
  3. PrimeQ[n];
  4. qQ::usage =
  5. "SqQ[n] is True when n is an exact square, and False otherwise.";
  6. (*We reduce n modulo a product of small primes and use*)
  7. (*pre-computed tables of Jacobi symbols to filters out*)
  8. (*most non-squares with a single multi-precision operation.*)
  9. (*We use IntegerQ[Sqrt[n]] on less than 1/11595 integers.*)
  10. (*Pre-computed variables starting in SqQ$ are for internal use;*)
  11. SqQ$m = (SqQ$0 = 59*13*7*5*3)*(SqQ$1 = 23*19*17*11)*(SqQ$2 =
  12. 47*37*31)*(SqQ$3 = 43*41*29);
  13. SqQ$u = SqQ$v = SqQ$w = SqQ$x = 0;
  14. Block[{j},
  15. For[j = SqQ$0, j-- > 0,
  16. SqQ$u +=
  17. SqQ$u + If[
  18. JacobiSymbol[j, 59] < 0 || JacobiSymbol[j, 13] < 0 ||
  19. JacobiSymbol[j, 7] < 0 || JacobiSymbol[j, 5] < 0 ||
  20. JacobiSymbol[j, 3] < 0, 1, 0]];
  21. For[j = SqQ$1, j-- > 0,
  22. SqQ$v +=
  23. SqQ$v + If[
  24. JacobiSymbol[j, 23] < 0 || JacobiSymbol[j, 19] < 0 ||
  25. JacobiSymbol[j, 17] < 0 || JacobiSymbol[j, 11] < 0, 1, 0]];
  26. For[j = SqQ$2, j-- > 0,
  27. SqQ$w +=
  28. SqQ$w + If[
  29. JacobiSymbol[j, 47] < 0 || JacobiSymbol[j, 37] < 0 ||
  30. JacobiSymbol[j, 31] < 0, 1, 0]];
  31. For[j = SqQ$3, j-- > 0,
  32. SqQ$x +=
  33. SqQ$x + If[
  34. JacobiSymbol[j, 43] < 0 || JacobiSymbol[j, 41] < 0 ||
  35. JacobiSymbol[j, 29] < 0, 1, 0]]];
  36. (*The function itself starts here*)
  37. SqQ[n_Integer] :=
  38. Block[{m = Mod[n, SqQ$m]},
  39. BitGet[SqQ$u, Mod[m, SqQ$0]] == 0 &&
  40. BitGet[SqQ$v, Mod[m, SqQ$1]] == 0 &&
  41. BitGet[SqQ$w, Mod[m, SqQ$2]] == 0 &&
  42. BitGet[SqQ$x, Mod[m, SqQ$3]] == 0 && IntegerQ[Sqrt[n]]]
  43. (*Automatically thread over lists*)
  44. SetAttributes[SqQ, Listable];
  45.  
  46. u0 = u = Block[{$MaxExtraPrecision = 1000}, Ceiling[Sqrt[n]]];
  47. v = u^2 - n;
  48. While[! SqQ[v], v += u; v += u += 1];
  49. p = u - Sqrt[v];
  50. q = n/p;
  51. {u - u0, p, q}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement