def problem16(base, pow): """ >>> problem16(2, 1000) 1366 """ value = lib.power(base, pow) return sum(lib.digits(value))
def problem29(a, b): """ return no.of distinct terms in the sequence generated by a power b for 2 <= a <= 100 and 2 <= b <= 100? >>> problem29(2, 101) 9183 """ L = range(a, b) result = len(set([lib.power(x, y) for x in L for y in L])) return result
def power_test(): x = 2 y = 2 m = 3 fn_res = power(x, y, m) actual_result = (x**y) % m if fn_res != actual_result: print('fast modular exponentiation failed') return False else: print('fast modeular exponentiation passed') return True
def test_power(): assert lib.power(2, 2) == 4 assert lib.power(2, 3) == 8
def pow(): x = int(request.args.get('x')) y = int(request.args.get('y')) m = int(request.args.get('m')) return str(power(x, y, m))