How many powers of a prime factor in a number 
I have a number $K$ that can be expressed as $$K = a^pb^qc^r$$ where each of $a$, $b$ and $c$ are prime numbers. Given $K$ and $a$, how do I find out the value of $p$? 

I initially thought of taking the log of $K$ with $a$ as the base but that would return a number $m$, such that $a^m$ is less than (or equal in case $q$ and $r$ are both zero) and is not necessarily a divisor of $K$. I have a feeling the solution is straight forward but can't seem to figure it out. Any help would be great.
EDIT
The other thing I thought of was repeated division by the prime until the division returns a remainder. But is there a single step solution?
 A: This is an answer to the final OP's question: 

The other thing I thought of was repeated division by the prime until the division returns a remainder. But is there a single step solution?

If you are trying to represent that function in a single step for an specific theoretical purpose, well you can do it. It is not useful, but theoretically correct (in the style of G.H.Hardy's 'A formula for the prime factors of any number'). It is just a curiosity:

$p=\sum_{t=1}^{\infty} (1-\lceil{\frac{K}{a^t}-\lfloor\frac{K}{a^t}\rfloor}\rceil)$

The expression $\lceil{\frac{K}{a^t}-\lfloor\frac{K}{a^t}\rfloor}\rceil$ will be $0$ if $a^t$ is a divisor of $K$ (no decimals), and $1$ if $a^t$ is not a divisor of $K$ because there are decimals in the division, so the result is a number in the interval $(0,1)$, and the ceil of such decimal number will be always $1$.
For that reason, only the $t$ exponents that make $a^t$ a divisor of $K$ will make the expression $$(1-\lceil{\frac{K}{a^t}-\lfloor\frac{K}{a^t}\rfloor}\rceil)=(1-0)=1$$ ...equal to $1$. So counting the $1$'s we will obtain the value of $p$.
E.g.:
$24=2^3 \cdot 3$
$K=24, a=2$

$p=\sum_{t=1}^{\infty} (1-\lceil{\frac{24}{2^t}-\lfloor\frac{24}{2^t}\rfloor}\rceil)= 1 + 1 + 1 + 0 + 0 \cdots = 3$

