Is there any algorithm or something to solve $\phi\left(x\right)=n$ Solve for $x$, the following equation: $$\phi\left(x\right)=12$$ where $\phi$ is Euler's totient function $\phi\left(n\right)$ is the number of numbers less than or equals $n $ such that $gcd\left(n,a_i\right)$ with $1\le a_i \le n$, in other words :
$$\phi(n)=\mid \{a\in \mathbb N : 1\le a\le n\gcd(a,n)=1\}\mid$$I'm interested in general solution of this equation  $$\phi\left(x\right)=n$$
 A: First factor $n$ to find all of its divisors. Only if $d\mid n$ and $p=d+1$ is prime and $p^k\|x$ (where possibly $k=0$) then $p$ may occur as divisor of $x$ up to $(k+1)$st power. So once you have determined such a prime $p$, try $x=p^rx'$ with $1\le r\le k+1$ and solve recursively $\phi(x')=\frac {n}{\phi(p^r)}$ (with $p\nmid x'$).
Example: With $n=12$ we have divisors $1,2,3,4,6,12$ and prime candidates $2,3,5,7,13$.


*

*If $2$ is the smallest prime dividing $x$, try $\phi(x')=12$, $\phi(x')=6$, $\phi(x')=3$ with $x'$ odd. The first allows (see below) $x'=21$ and $x'=13$, so we get $x=42$ and $x=26$ as solutions. The second allows $x'=7$ and $x'=9$ (as can be found by the same method), so we get $x=28$ and $x=36$. The last is not possible because $\phi(x')$ must be even unless it is $=1$.

*If $3$ is the smallest prime dividing $x$, try $\phi(x')=6$, $\phi(x')=2$ with $x'$ divisible only by primes $>3$. Only the first s possible and only with $x'=7$. This gives us $x=21$ as a solution

*If $5$ is the smallest prime dividing $x$, try $\phi(x')=3$ with $x'$ divisible only by primes $>5$. This is not possible.

*If $7$ is the smallest prime dividing $x$, try $\phi(x')=2$ with $x'$ divisible only by primes $>7$. This is not possible.

*If $13$ is the smallest prime dividing $x$, try $\phi(x')=1$ with $x'$ divisible only by primes $>13$. This is in fact possibly with $x'=1$. So $x=13$ is a solution.

