Exemplo n.º 1
0
def problem16(base, pow):
    """
    >>> problem16(2, 1000)
    1366
    """
    value = lib.power(base, pow)
    return sum(lib.digits(value))
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
def test_power():
    assert lib.power(2, 2) == 4
    assert lib.power(2, 3) == 8
Exemplo n.º 5
0
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))