Problem with calculating the correct value for $(p-1)*(q-1)$? I came to a problem when calculating some values for RSA encryption task.

So the data I have is this:

$e*d=81$

$C=5$

Now I have to calculate the original message($m$) and I have an issue because I can see what the solution for $m$ should be, but I get a different answer.

So far, I was able to figure out that $e=27$ and $d=3$.

Now I should calculate $m=(p-1)*(q-1)$ with the equation: $e*d \bmod m = 1$.

But the solution I have from this example says that $m=40 \rightarrow 4*10$ which gives us $p=5$ and $q=11$.

Now my question is why is $40$ correct and not $m=20 \rightarrow 2*10 \rightarrow p=3$ and $q=11$, which is what I got?
So, you're given the exponents (and the ciphertext), and are expected to recover the modulus?  That's certainly not the standard way of using RSA.

It turns out that the necessary and sufficient conditions on $p, q$ is that $p-1, q-1$ are factors of $ed-1$; hence we know that $p, q \in \{ 3, 5, 11, 17, 41 \}$ (as those are the primes that meet this criteria), and any such combination of distinct $p, q$ would work (we also know that $pq &gt; c$, however all combinations meet this criteria); by work, I mean that $(m^e)^d \equiv m \bmod{pq}$ for all messages $m$.  Now, with some combinations, the $e, d$ combination might not be minimal; however nonminimal $e, d$ values do happen in practice.

As both $p, q = 5, 11$ and $p, q = 3, 11$ meet the above criteria, both lead to valid answers.  If the original question did not add any additional information, well, they did not specify the question sufficiently.