On the tails of Solution 1, you have a couple of things that you might do to improve the speed a bit...

Don't add to the pointer but increment it instead.

intgr[i]= getmod(power(*(str++),a),b);

The std library pow method uses floats. This means that the function has to be concerned with fractional powers. With integers, you don't need that overhead.

If you know that you're only going to use integers, then write your own version and make it inline or a template.

The compiler may be able to further optimize the code when it is inline.

You may look at similar optimizations for mod()

Example / Note that you can't use negative values for the exponent.

#include "stdafx.h"
#include <conio.h>
#include <math.h>
template <class T0, class T1, class T2>
T0 _power(T1 v, T2 exp)
{
T0 result = 1;
while (exp--)
result *= v;
return result;
}
int _tmain(int argc, _TCHAR* argv[])
{
unsigned int a = 2;
unsigned int b = 3;
unsigned __int64 c = _power<unsigned __int64, unsigned int, unsigned int>(a, b);
printf("%I64u", c);
_getch();
return 0;
}

If this is your own code, it could be bad; one example of prohibitively bad solution is multiplication of

`y`

operands.—SA