Here you are always calling `div(_n, f)` twice, so it's a waste. I would do:
```c++
RCP<Basic> d = div(_n, f);
while (is_a<Integer>(*d)) {
    count++;
    _n = d;
    d = div(_n, f);
}
```