RSA: Is possible get p and q from this d and n?
I'll assume that $p$ and $q$ are prime.

Here's one approach to recover them


Step 1: recover $l = d^{-1} \bmod n$
Step 2: select a random $x$ and compute $y = x^l \bmod n$


Here's why such a $y$ is interesting.

We have $y \equiv 1 \pmod q$ (because $l$ is a multiple of $q-1$); similarly, we have $y \equiv 1 \pmod p$.  However, if we consider $y \bmod p^2$, the group order of $\mathbb{Z}^*_{p^2}$ is $p(p-1)$; $l$ is unlikely to be a multiple of that (and will never be if $p$ and $q$ are the same size), and so we have (with great likelihood) $y \not\equiv 1 \pmod{p^2}$


Step 3: compute $z = \gcd(y-1, n)$


$y-1$ is a multiple of $pq$, but not a multiple of $p^2q$, hence $z$ will be $pq$.

Then, it's trivial, $p = n/z$ and $q = z/p$



Now, the above might not work if the prime values $p$ and $q$ were deliberately selected to have $y \equiv 1 \pmod n$ consistently.  However, we have another method:


Step 2': set $l_0, k$ such that $l_0 = l / 2^k$ is odd
Step 3': select a random $x$ and compute $y_0 = x^{l_0} \bmod n$
Step 4': for $i := 0 .. k-1$

Check if $x_i = 1$; if so, fail (and go back to step 3' and select a different x)

Check if $\gcd(x_i - 1, n) \neq 1$; if so, that gives you a nontrivial factor of $n$ (and return success; completing the factorization should be straight-forward)

Otherwise, compute $x_{i+1} = x_i^2 \bmod n$


Here's how the above works; we know that we'll have $x_k = x^l \bmod n = 1$, and so $x_i \bmod p$ and $x_i \bmod q$ will both become 1 at some point in the computation; however it is likely that they'll become 1 at different points in the process; that is, one of them will become 1 first (and if so, the gcd will catch it)