Oh, got it, thanks!
Just 1 more query....regarding your print statement in the main function
Shouldn't you just print nonPeriodicStrs % m?
Thanks a lot. It's mostly clear, but I didn't understand your modMexp function....
Like, for n=m=3,
res=1, then res=2 and then res=2; res=4, res=1; res=2, res=2 (finally)
So, for 2^2, isn't your program calculating ((2 mod m)2)mod m instead of (2 mod m)(2 mod m)mod m