Checking work with modular arithmetic on large numbers

Just learned about congruence and the general principle of remainder arithmetic. I wanted to double check my work with the following example:

Find remainder:$$rem(9876^{3456789}(9^{99})^{5555}-6789^{3414259},14)$$

Step 1: Replace 9 with $3^2$ and multiply the exponents to yield $3^{1099890}$ $$rem(9876^{3456789}3^{1099890}-6789^{3414259},14)$$

Step 2: Find $rem(9876,14) = 6$ and $rem(6789,14)=13$ $$rem(6^{3456789}3^{1099890}-13^{3414259},14)$$

Step 3: Look for pattern in the exponential powers.
a) Powers of 6: even have remainder of 8, odd have remainder of 6. Thus $rem(6^{3456789},14) = rem(6,14)$
b) Powers of 13: even have remainder of 1, odd have remainder of 13. Thus $rem(13^{3414259},14) = rem(13,14)$
c) Powers of 3: Slightly more complicated but there is a repeating pattern of 6 remainder values (e.g. $rem(3^{n},14) = rem(3^{n+6k},14)$, $k$ $\epsilon$ $\mathbb N $). We can simplify by taking $rem(1099890,6) = 0$, thus $rem(3^{1099890},14) = rem(3^0,14)$

With those simplifications we now have: $$rem(6 \cdot 1 - 13,14) = rem(-7,14) = 7$$

I am guessing there is a more elegant solution to this as well...


Note that the number is odd since it is the difference of an even and odd number.

Now, consider the number modulo $7$.

$9876\bmod7=-1$, $9\bmod7=2$, $6789\bmod7\equiv-1$.

So, we can rewrite as $$(-1)^{3456789}(2^{99})^{5555}-(-1)^{3414259}\bmod7$$Note that by Fermat's Little Theorem, $a^6\equiv1\bmod7$ for all $a$ such that $7\not\mid a$. In particular, $2^{99}\equiv8\equiv1\bmod7$, so $(2^{99})^{5555}\equiv1\bmod7$.

Putting this all together, we get $$(-1)-(-1)\bmod7$$

So, our number is $\equiv0\bmod7$ and odd, so the remainder by the Chinese Remainder Theorem is $7\bmod{14}$.