Prime conditional problem in modulo Any odd prime p can be written in the form of $x^2 + y^2$ when $p \equiv 1 \pmod{ 4}$. explain the proof.  Is there any such condition equations and satisfying the primes? if there, how to construct them? Also, is there any function, which will give a prime.
Regarding the proof: Here's an elementary argument. It can be modified to the following similar problems:


$x^2 + 2y^2 =p \leftrightarrow p \equiv 1,3 \mod 8$ or $p=2$.
$x^2+ 3y^2 = p \leftrightarrow p \equiv 1 \mod 3 $ or $p=3$.


Neccesity: Note that for any $x,y$, we have $x^2+y^2=0,1,2 \mod 4$, so for it to be a prime $p$ we need either $p=2$, or $p= 1 \mod 4$.

Sufficiencty: If $p=2$, $x=y=1$ will work. If $p \equiv 1 \mod 4$, then $t^2 + 1 = 0 \mod p$ is solvable, as it is equivalent to finding an element of order 4 in $(\mathbb{F}_{p})^{\times}$, which is a cyclic group of order $p-1$, i.e. divisible by $4$, so you can just take $t=g^{\frac{p-1}{4}}$ for any generator $g$.

By the pigeonhole principle, two of the elements $\{ ta-b \mod p| 0 \le a,b &lt; \sqrt{p} \}$ are the same mod $p$, say: $ta-b=ta'-b' \mod p$, i.e. 
$$t(a-a')=(b-b') \mod p$$
Square both sides of the last equation and move both terms to same side to get: $(b-b')^2 + (a-a')^2 \equiv 0 \mod p$. Note that $|a-a'|,|b-b'| &lt; \sqrt {p}$, so $0&lt; (b-b')^2 + (a-a')^2 &lt; 2p$, implying:
$$(b-b')^2 + (a-a')^2 = p$$

Regarding more such conditions - I suggest the wonderful book "Primes of the form $x^2 + ny^2$" by David A. Cox. Another related book is "Introduction to the Construction of Class Fields" by Harvey Cohn.

Regarding a prime-generating function: consult this Wikipedia page. There are many formulas, most of them impractical. But there's a system of Diophantine equations "defining" the primes, which is maybe what you're looking for.
I do not know the prime function. It is my out of expectation. We can create your cited type problems. For example, primes can be written as primes $x^2$ + 2$y^2$ if and only if p = 1 or 3 (mod 8). Regarding your first question:

Let L = (1, 0, 1) and L has discriminant = -4. If (a, b, c) is reduced representative of some equivalence class with |b| &lt; or = a &lt; or = |c| => $b^2$ = 4(ac -1). Since |ac| > or = $b^2$, we should have ac -1 = 0. The only form of L is (1, 0, 1). Thus h (-4) = 1 and p can be expressible by (1, 0, 1) if and only if -4 = () (mod 4p). I hope you can do the necessary things to complete the solution of  $x^2$ + 2$y^2$ if and only if p = 1 or 3 (mod 8). 
All the best!