We want to determine the number of times a prime number $p$ divides a number $n$ or, in other words, determine the greatest integer $k$ such that $p^k\ |\ n$.
Is there a better method than trying naive division successively?
We want to determine the number of times a prime number $p$ divides a number $n$ or, in other words, determine the greatest integer $k$ such that $p^k\ |\ n$.
Is there a better method than trying naive division successively?
In general, there are several integer factorization algorithms, which are sometimes better than just naive division. See also this MSE-question. For some integers, there is an explicit formula for the multiplicity, e.g., for $n=N!$. In fact, the highest power of a prime $p$ dividing $N!$ is given by
$$\nu_p(N!) = \left \lfloor \frac{N}{p} \right \rfloor + \left \lfloor \frac{N}{p^2} \right \rfloor + \left \lfloor \frac{N}{p^3} \right \rfloor + \cdots$$
The main difficulty often is to find any prime dividing our integer $n$. For example, which prime divides $ n=1167984798111281975972139931059274579165801700195500732513291383783133049$ $58815197564537037428785261488414688806744251221941374876801065757257538498$ $6457405973985247465176041951676954461208131403777$
Once you have discovered that $$ p=2^{127}-1 $$ is a prime divisor, it is easy to see that $p^2$ does not divide $n$.
From $i=0$ keep on dividing by ascending powers $p^{2^i}$ until a non-zero remainder is found (while storing these powers, note that the next power is just a squaring), then divide by the stored descending powers giving a zero remainder.
– gammatester Sep 14 '17 at 15:18