ad 1: In base 2, $y$ reads:·
$$y=12345 = 11\,0000\,0011\,1001_2$$
i.e. in order to perform $x^y\bmod n$ you need
- $5=\operatorname{popcount}(y)-1\quad$ times (Mul + Mod)
- $13 = \operatorname{bitlen}(y) - 1\quad$ times (Square + Mod)
assuming you start expansion at the most significant bit of $y$. Hence the number of modular operations needed is:
$$18\times\text{Mul}+18\times\text{Mod}$$
under the assumption that squaring performs no better than multiplying. Notice however that $$n = 9\,087\,654\,321 \geqslant 2^{32}=4\,294\,967\,296$$
and therefore when you are multiplying two numbers in $[0,n)$, then the result will not fit in a 64-bit register in general. (Using signed residues in $[-n/2, n/2]$ won't help). Using 70-bit arithmetic would be sufficient though.
For part 2 of the question depends on what algorithm you are using. You want to compute the discrete logarithm, which is costly.
a·b=(a*n) mod n. You can of course implemend multiplication by hand and then intermediate results won't exceed $2n$. – emacs drives me nuts Sep 02 '22 at 20:45