Subrings of rational numbers (UFD, associated prime elements) 
Let $\Pi$ - be all prime natural numbers, $\pi \subset \Pi$, $ |\pi| < \infty $.
  $ \Bbb Q^{(\pi)} $ - all rational numbers which denominators are mutually prime with elements of $ \Pi \setminus \pi $, and $ \Bbb Q_{\pi} $ - all rational numbers which denominators are mutually prime with elements of $ \pi $.
  I need to prove that $ \Bbb Q^{(\pi)} $ is a unique factorization domain (UFD) with infinite set of associated prime elements, and $ \Bbb Q_{\pi} $ is also a UFD, but it's set of associated prime elements is finite.

The problem I'm facing is at the very beggining - I can't understand what are the prime elements of $ \Bbb Q_{\pi} $ and $ \Bbb Q^{(\pi)} $. In case of $ \Bbb Q_{\pi} $ I have some thoughts that they can be represented in form of $ \frac {n \cdot p}{m} $ where $n$, $m$ - any from $ \Bbb Z $ mutually prime with $\pi $ and $q$ - any from $\pi$ (definition of prime works on such elements in $ \Bbb Q_{\pi} $) but I can't prove that these are the only prime elements in $ \Bbb Q_{\pi} $.
I would be very grateful for a direction of thought or a reference to a similar task.
 A: Consider $S_\pi\subset \mathbb{Z}$ be the multiplicative set generated by finite set $\pi$. Then $\mathbb{Q}^{(\pi)}$ is the localization of $\mathbb{Z}$ with respect to $S_\pi$; i.e. $\mathbb{Q}^{(\pi)}=S_\pi^{-1}\mathbb{Z}$. Due to general properties of localization, prime ideals of $Q^{(\pi)}$ are of the form $S_\pi^{-1}\mathfrak{p}$ where $\mathfrak{p}\subset \mathbb{Z}$ is a prime ideal such that $\mathfrak{p}\cap S_\pi=\emptyset$. Since $\mathbb{Z}$ is a PID, $\mathfrak{p}=(p)$ for some $p\in \Pi\setminus\pi$. Therefore all prime ideals of $Q^{(\pi)}$ are of the form $p\: Q^{(\pi)}$ with $p\in \Pi\setminus \pi$.

A ring is a UFD if every non-zero prime ideal contains a prime element. [Kaplansky, Commutative Rings, Ch. 1, Thm. 5].

Since $p/1\in Q^{(\pi)}$ is clearly a prime element if $p$ is prime, then $Q^{(\pi)}$ is a UFD.
Similarly for $\mathbb{Q}_\pi$ define $T_\pi$ as the multiplicative set generated by $\Pi\setminus \pi$. Then $\mathbb{Q}_\pi=T_\pi^{-1}\mathbb{Z}$. In the same fashion one shows $Q_\pi$ is a UFD. The difference is prime ideals of $Q_\pi$ are all of the form $p\: Q^{(\pi)}$ with $p\in \pi$. Since $\pi$ is a finite set, $Q_\pi$ has a finite number of prime ideals.
Edit: Since you asked:

Theorem: A non-zero ideal $\mathfrak{q}\subset S^{-1}R$ is prime if and only if $\mathfrak{q}=\mathfrak{p}S^{-1}R$ with $\mathfrak{p}\subset R$ a non-zero prime ideal such that $\mathfrak{p}\subset R$ is prime and $\mathfrak{p}\cap S=\emptyset$.

Proof: $\Longleftarrow$ Consider $\mathfrak{p}$ like above. Suppose $a/s, b/t\in S^{-1}R$ are such that $ab/st\in \mathfrak{p}S^{-1}R$. Then there exists $p\in \mathfrak{p}$ and $r\in S$ such that $ab/st=p/r$. Therefore there exists $f\in S$ such that $(abr-pst)f=0$. Since $0\in \mathfrak{p}$, this means $abr\in \mathfrak{p}$. Since $\mathfrak{p}\cap S=\emptyset$, then $r\notin S$. So $ab\in \mathfrak{p}$. So either $a\in \mathfrak{p}$ or $b\in \mathfrak{p}$. Therefore either $a/s\in \mathfrak{p}S^{-1}R$ or $b/r\in \mathfrak{p}S^{-1}R$ and  $\mathfrak{p}S^{-1}R$ is consequently prime.
$\Longrightarrow$ Suppose $\mathfrak{q}\subset S^{-1}R$ is prime. Consider the homomorphism $\phi: R\to S^{-1}R$ which sends $a\mapsto a/1$ (check this is actually a homomorphism). Now if $f: A\to B$ is any homomorphism and $\mathfrak{q}\subset B$ is a prime ideal, then $f^{-1}(\mathfrak{q})\subset A$ is also a prime ideal (prove it). Let $\mathfrak{p}=\phi^{-1}(\mathfrak{q})$, then in this example $\mathfrak{p}\cap S=\emptyset$ too (again not hard to show). Then (I leave it as an exercise) $\mathfrak{q}=\mathfrak{p}S^{-1}R$.
