thank you, that is the what I need. I am very surprised, that standard mod function in Matlab does not work well for me, even if input is relatively small, e.g. mod(8^51,103) produce
1.267650600228229e+030 instead of 58. Has anybody idea, why it is so?