30^74 mod 57 = (3^74 * 10^74) mod 3*19 = 3 * [(3^73 * 10^74) mod 19]
and
(3^73 * 10^74) mod 19 = (3^(18*4) * 3 * 10^(18*4) * 10^2) mod 19
now, by a Fermst's Little Theorem ( m^(p-1) mod p = 1):
(3^73 * 10^74) mod 19 = (3 * 10^2) mod 19 = 300 mod 19 = 15
therefore
30^74 mod 57 = 3 * 15 = 45
The basic implementation of modular exponentiation method to get the remainder is:
long modular_pow( long base, long exponent, long modulus) {
long c = 1;
for ( long e_prim = 0; e_prim < exponent; ++e_prim) {
c = (c * base) % modulus;
}
return c;
}
however implementation shown by @Vikram Bhat is more efficient.