There are some bignum packages floating around, e.g. the the open source MPArith package from http://www.wolfgang-ehrhardt.de/mp_intro.html. With the included demo calculator you can easily beat your time limit:
D:\Xtools\MPArith>t_calc.exe
T_CALC using MPArith V1.26.05 (31/32 bit) [mp_calc] (c) W.Ehrhardt 2006-2013
Karatsuba cutoffs: mul/sqr = 16/32, Toom-3 cutoffs: mul/sqr = 32/64
Burnikel/Ziegler div cutoff = 32, MaxBit = 520093696, MaxFact = 22623931
Type "?<enter>" to get some info about commands, "\q" or "quit" to end.
[D]:=> 10^100000 mod (10^8-1)
Result = 1
[D]:=> .
Time = 20.128 ms
[D]:=> 10^100000;
Result = [>0, 332193 bits, chksum=$CE01C341, time=46.994 ms]
But depending on your requirements and examples you may even get your results
without bignum packages. If you want to compute a ^ b mod n
you do not
compute a ^ b
and then reduce mod n
in a second step, but you reduce every product in a loop. And
you should use fast binary exponentiation, see e.g. the description and pseudo
code at http://en.wikipedia.org/wiki/Modular_exponentiation.
For modules n of order 10^8 you need to reduce a product of two 31/32 bit integers
and therefore you need int64
or so to accumulate the products (which should not be a problem for you Pascal version which has QWord
). I guess such a program would be much faster than the MPArith bignum
code with it's 20 milliseconds.