1

How do you solve $x*x = 1009732533765288 \mod 1009732533765289$? Wolframalpha when you plug that in has the answers as:

$x \equiv 389427288088687 \mod 1009732533765289$

and

$x \equiv 620305245676602 \mod 1009732533765289$

both of $389427288088687 + 620305245676602 = 1009732533765289$. I'm wondering how it solves these so I can write a program to solve these types of equations. Thanks.

offline
  • 974
  • 8
    This is easier to solve when you observe that this is equivalent to $$x^2\equiv-1\bmod{1009732533765289}$$ – Rushabh Mehta Mar 29 '21 at 19:13
  • 1
    Observe that $1009732533765289$ is a prime number and if $x^2 \equiv a \pmod n$, then $(-x)^2 \equiv a \pmod n$. You now can use a Wilson's Theorem argument to find one value for $x$. – Sávio Mar 29 '21 at 19:24
  • $A + B =M$ should not be surprising as $A+B = M \implies B \equiv - A \pmod M$ and $A^2 \equiv (-A)^2$. So if we have $x^2 =k$ you will always have a pair of solutions that add to $M$. So we want $A^2 +1 \equiv 0 \pmod M$. – fleablood Mar 29 '21 at 19:26
  • 3
    "Observe that 1009732533765289 is a prime number" I'm not sure how to "observe" that. :) – fleablood Mar 29 '21 at 19:31
  • it's odd and has a 2 mod 3 difference in quantity of 1 mod 3 digits and 2 mod 3 digits, therefore it's $6k\pm 1$ at least – Roddy MacPhee Mar 29 '21 at 19:39
  • 1
    Out of curiosity, where did this problem come from? Or, maybe more directly, 'why $1009732533765289$?'. – Steven Stadnicki Mar 29 '21 at 19:45
  • @StevenStadnicki I noticed that many primes have a solution where the answers added together equal the prime, so I chose 1009732533765289. It could have easily been 1009, whose answers are 469 and 540. I'm just looking for a solution on how to get the answers in the case the prime number i have is in the form as the other answers are saying it has. I don't think non primes have this feature, but i haven't tested too many numbers – oppressionslayer Mar 29 '21 at 19:49
  • @StevenStadnicki Also i noticed those answers always pass the 2nd pow(x, 2, z) part of the MillerRabin test, so i was interested in them in general. – oppressionslayer Mar 29 '21 at 20:07
  • @fleablood, of course, using some software. Why would someone make this math by hand? lol – Sávio Mar 29 '21 at 20:10
  • 1
    Use the Tonelli–Shanks algorithm (see https://en.wikipedia.org/wiki/Tonelli%E2%80%93Shanks_algorithm). – Steven Clark Mar 29 '21 at 22:04

1 Answers1

1

I am going to use the fact that the number is odd to avoid technicalities. Since your number has size approximately $10^{15}$ it can be factored in a variety of ways.

One could then solve it for each $p^k$. To do this one can find a primitive root $r$ in the normal way and just letting $x=r^{(p-1)p^k/4}$ or $x=r^{3(p-1)p^k/4}$ (there is no solution if $p$ is not congruent to $1\bmod 4$).

Then one can use the Chinese remainder theorem to find a solution that works for all primes simultaneously.

If the number is even we do the following: If the number is a multiple of $4$ there is no solution, and if the number is not a multiple of $4$ then just make sure that the number you get at the end with CRT is odd and we are good to go.

Asinomás
  • 105,651