コード例 #1
0
ファイル: euler_173.py プロジェクト: jessekrubin/pyEuler
def square_lams(upperlimit):
    divfours = [i for i in range(upperlimit + 1) if i % 4 == 0 and i > 4]
    total = 0
    for num in divfours:
        total += len([d for d in divisors_gen(num // 4)]) // 2

    return total
コード例 #2
0
def p174():
    divfours = [i for i in range(1000000 + 1) if i % 4 == 0 and i > 4]
    total = 0
    for num in divfours:
        num_lams = len([d for d in divisors_gen(num // 4)]) // 2
        if 0 < num_lams < 11:
            total += 1

    return total
コード例 #3
0
def p012():
    cur_tri = 1
    maxmax = 1
    i = 1
    while maxmax < 500:
        i += 1
        cur_tri += i
        numDivs = sum(1 for _ in divisors_gen(cur_tri))
        if numDivs > maxmax:
            maxmax = numDivs
    return cur_tri
コード例 #4
0
def prime_factors_gen(n: int) -> Iterator[Any]:
    """prime factors generator

    :param n: number to be factorized
    :type n: int

    .. doctest:: python

        >>> list(prime_factors_gen(12))
        [2, 3]
        >>> list(prime_factors_gen(16))
        [2]

    """
    return (p for p in divisors_gen(n) if is_prime(p))
コード例 #5
0
def prime_factors_gen(n):
    """prime factors generator

    Args:
        n (int): number to be factorized

    Yields:
        (int): prime factors w/o repeats

    Examples:
        >>> list(prime_factors_gen(12))
        [2, 3]
        >>> list(prime_factors_gen(16))
        [2]

    """
    return (p for p in divisors_gen(n) if is_prime(p))
コード例 #6
0
def sum_divisors(n):
    return sum(divisor for divisor in divisors_gen(n) if divisor < n)
コード例 #7
0
ファイル: euler_021.py プロジェクト: jessekrubin/pyEuler
def sum_proper_divisors(n):
    return sum(divisors_gen(n)) - n
コード例 #8
0
def proper_divisors_gen(n):
    return sum(number for number in divisors_gen(n) if number < n)