For a single integer $n > 1$, it's sufficient to iterate in order over the integers $2 \leq k \leq \sqrt{n}$ checking for divisibility. When you find a number that divides $n$, it will be prime (This is trivial to observe). You'd then divide out the instances of that prime from $n$ until it is no longer divisible by it.
This is not a good solution for a large set of integers however.
Computationally speaking, if you're working over a range like $(1, 10^9)$, a sieve is feasible. Not only would you sieve the primes up to $N$, you'd also sieve a sequence of the smallest prime factors for every integer up to $N$, which takes space linear in the value of $N$. The sieve would take $O(N\log\log N)$ time. Factorization would then be a sequence of divisions by the smallest prime factor of $n$ until you reach $1$. This gives you constant time per prime factor for an integer $n$.
Another method that uses sieves to make the first trivial division solution better is to sieve the primes up to the square root of the maximum value in your queries. This way, when performing trial division, you can directly iterate over the primes to check for divisibility.
If you're working over a very sparse set of integers, you'd need more sophisticated algorithms like Pollard's Rho Algorithm. A sieve is more useful when your range is sufficiently small and you want to work with a sufficient part of it.
When I first read your question, I thought of the Fermat Factorization trick. That is, I wasn't sure whether you expected a more computational answer or not. This trick works well with integers that have factors close to their square root.
Consider the integer $8051$ for instance. It's square root is $\approx 90$. It can be rewritten as $8100 - 49$. This is the difference of two squares:
$$8100 - 49 = (90 - 7) \times (90 + 7) = 83\times 97$$
Besides naive trial division and this trick, there isn't much you can do with the knowledge of the square root of an integer to get the factorization.